Like the title, can you not write it
phpcn_u15822017-05-16 13:41:53
i
是遍历元素的索引。
如原生的map
,forEach
Method.
['a', 'b', 'c'].map(function(item, i, array){
console.log(item, i, array);
});
['a', 'b', 'c'].forEach(function(item, i, array){
console.log(item, i, array);
});
item
为当前项,即当前遍历的元素本身。分别为a
, b
, c
i
为元素处于数组中的下标或索引。分别为 0
, 1
, 2
array
为数组本身。值为['a', 'b', 'c']
PHP中文网2017-05-16 13:41:53
i is the index corresponding to the item in the data and can be omitted
迷茫2017-05-16 13:41:53
Refers to the native map, item is a reference to the data item, i represents the index. i can be omitted
For example:
var arr = [1,2,3];
arr.map(function(item){
if(item == 2){
item = 100; // arr 是不会变成[1,100,3],因为 item 改变不影响原数组,它只是个引用
}
})
If it is like the following, arr will be changed
arr = arr.map(function(item){
if(item == 2){
item = 100;
}
return item
})