//将数组中布尔值为false的成员指为0 Array.from([1, ,2,3,3], x => x || 0) //[1,0,2,3,3] //将一个类似数组的对象转为一个数组,并在原来的基础上乘以2倍 let arrayLike = { ‘0‘: ‘2‘, ‘1‘: ‘4‘, ‘2‘: ‘5‘, length: 3 } Array.from(arrayLike, x => x*2) //[4,8,10] //将一个set对象转为数组,并在原来的基础上乘以2倍 Array.from(new Set([1,2,3,4]), x => x*2) //[2,4,6,8]
Array.from({length:3}, () => ‘jack‘) //["jack", "jack", "jack"] Array.from({length:3}, item => (item = {‘name‘:‘shao‘,‘age‘:18}))
//[{‘name‘:‘shao‘,‘age‘:18}, {‘name‘:‘shao‘,‘age‘:18}, {‘name‘:‘shao‘,‘age‘:18}] Array.from({length: 2}, (v, i) => item = {index:i});//生成一个index从0到4的数组对象[{index: 0},{index: 1}]
Array.from(‘abc‘) //[‘a‘,‘b‘,‘c‘]
原文:https://www.cnblogs.com/shaofl/p/10521660.html