const myArr=[1,5,3,4,2];
const [first,second] = myArr; # 提取前两个元素
console.log(first);
console.log(second);
展开/折叠结果
1
5
const myArr=[1,5,3,4,2];
const [,,third] = myArr; # 提取第3个元素
console.log(third);
展开/折叠结果
3
const myArr=[1,5,3,4,2];
const [,second,...anyE] = myArr # 提取第2个元素和以后
console.log(second);
console.log(anyE);
展开/折叠结果
5
(3) [3, 4, 2]
发表评论