任何编程语言都具有超出基本用法的功能。这个要归功于成功的设计和它试图解决的广泛问题。
Array.from():一个允许对js集合(数组,类数组对象,字符串,映射,集合等可迭代对象)进行大量有用转换的主力。
基本语法:
Array.from(arrayLikeOrIterable[, mapFunction[, thisArg]])
- arrayLikeOrIterable:必传参数,类数组对象或者一个iterable
- mapFunction:可选参数,mapFunction(item,index){ ... }对集合中的每一个项目调用的函数,返回的值被插入到新的集合中。
- thisArg:可选参数,执行回调函数mapFunction时this对象,这个参数很少使用。
例如:我们将类数组对象数量乘以2:
const someNumbers = { '0':10, '1': 15, length: 2};
Array.from(someNumbers, value => value * 2); // [20, 30]
-
将类数组对象转换成真正的数组 </