为什么阵列(100).MAP((_,ⅰ)= I标记+ 1)的不返回[1,2,...,100]? [英] Why Array(100).map((_, i) => i + 1) doesn't return [1, 2, ..., 100]?

查看:88
本文介绍了为什么阵列(100).MAP((_,ⅰ)= I标记+ 1)的不返回[1,2,...,100]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得很奇怪,

Array(100).map(function (_, i) { return i + 1; })

收益 [不确定的,不确定的,...,不确定] ,而不是 [1,2,...,100] ,我。即映射不会发生。相反,从100 未定义工作(的演示)。

returns [undefined, undefined, ... , undefined] rather than [1, 2, ..., 100], i. e. the mapping not happening. On the contrary, starting with an array of 100 undefined works (demo).

是否阵列(100)返回比其他东西100 未定义元素?

Does Array(100) returns something other than 100 undefined elements?

推荐答案

从的 Array.prototype.map 引用

回调仅适用于已指定数组的索引调用
  值;它不调用的指标是不确定的,那些
  已被删除或已从未被分配的值。

"callback is invoked only for indexes of the array which have assigned values; it is not invoked for indexes that are undefined, those which have been deleted or which have never been assigned values."

这是你创建阵列阵列(100)为100的长度,但目前还没有在它的项目。那些包含未定义,另一方面100个项目组成的数组有100个项目有一个值(即值未定义),因此回调将被调用为他们每个人。

The array that you create with Array(100) has a length of 100, but there are not items in it. An array containing 100 items that are undefined on the other hand has 100 items that have a value (that is the value undefined), so the callback will be called for each of them.

这篇关于为什么阵列(100).MAP((_,ⅰ)= I标记+ 1)的不返回[1,2,...,100]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆