来自MDN Web Docs , Array.from(obj, mapFn, thisArg)
与 Array.from(obj).map(mapFn, thisArg) 具有相同的结果,
只是它不创建中间数组。
This is especially important for certain array subclasses, like typed arrays, since the intermediate array would necessarily have values truncated to fit into the appropriate type.
“Array.from() 不会创建中间数组”是什么意思?
最佳答案
您可以将Array.from(obj).map(mapFn, thisArg)
分解为
const arr1 = Array.from(obj);
const arr2 = arr1.map(mapFn, thisArg);
由于 Array.from()
和 Array.prototype.map
都返回一个新数组,因此已经创建了两个数组。
Array.from(obj, mapFn, thisArg)
创建单个数组。
关于javascript - "Array.from() does not create an intermediate array"是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60899692/