javascript - "Array.from() does not create an intermediate array"是什么意思?

标签 javascript arrays

来自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/

相关文章:

javascript - Mongoose 从对象数组中的对象值返回数组,无需 JS 工作

javascript - 设置单选按钮在数据表中检查并使用数据库中的记录

javascript - Node/Express 未将更新的公司信息保存到数据库

python - 将函数应用于元组数组

c - 为什么我不能在第一个代码中将五个字符输入到数组中,但在使用第二个代码中所示的 getchar() 时可以?

javascript - 如何从javascript中的两个json数组中获取不匹配的对象

javascript - setTimeout 在 "change"事件处理程序中,但仅适用于不同的调用者

javascript - for循环只返回reactJS中的初始索引

php - 使用 PHP 从多维数组中删除第一个元素

c++ - 从结构数组中提取结构成员