
上QQ阅读APP看书,第一时间看更新
Using the from method
The Array.from method creates a new array from an existing one. For example, if we want to copy the array numbers into a new one, we can use the following code:
let numbers2 = Array.from(numbers);
It is also possible to pass a function so that we can determine which values we want to map. Consider the following code:
let evens = Array.from(numbers, x => (x % 2 == 0));
The preceding code created a new array named evens, and a value true if in the original array the number is even, and false otherwise.