Array.from()
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]
在 Array.from 中使用箭头函数
//使用箭头函数作为映射函数
//操纵元素
Array.from([1, 2, 3], x => x + x);
// [2, 4, 6]
//生成一系列数字
//由于数组在每个位置都用“undefined”初始化,
//下面的'v'值将为'undefined'`
Array.from({length: 5}, (v, i) => i);
// [0, 1, 2, 3, 4]
Array.from与Set
const lowerWord = Array.from(item.toLowerCase())
等效于
const lowerWord = [...new Set(item.toLowerCase())]