JS--Array.from() 方法从一个类似数组或可迭代对象创建一个新的,浅拷贝的数组实例

console.log(Array.from('foo'));
// expected output: Array ["f", "o", "o"]

console.log(Array.from([1, 2, 3], x => x + x));
// expected output: Array [2, 4, 6]

console.log(Array.from({length:10}, (_,key) => key));
// expected output: Array [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

=>

> Array ["f", "o", "o"]
> Array [2, 4, 6]
> Array [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

 

posted @ 2020-07-14 09:55  lishidefengchen  阅读(274)  评论(0编辑  收藏  举报