JavaScript 的 数组解构
等级 3130 次按键
使用带有剩余运算符的数组解构来提取元素。
JavaScript 代码
// 创建颜色名称数组1const colors = ["red", "green", "blue", "yellow"];// 数组解构按位置赋值: first = "red", second = "green"// ...rest将剩余元素收集到新数组中2const [first, second, ...rest] = colors;// 输出第一个元素3console.log(first);// 输出rest数组: ["blue", "yellow"]4console.log(rest);运行结果
red [ 'blue', 'yellow' ]
可以用这段代码练习打字。成绩不会计入排行榜。
这段代码中的符号
这段 JavaScript 代码中需要输入的符号及其出现次数。
"× 8,× 5.× 5;× 4(× 2)× 2[× 2]× 2=× 2