Like the title, can you not write it
i是遍历元素的索引。如原生的map,forEachMethod.
i
map
forEach
['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, ci为元素处于数组中的下标或索引。分别为 0, 1, 2array为数组本身。值为['a', 'b', 'c']
item
a
b
c
0
1
2
array
['a', 'b', 'c']
i is the index corresponding to the item in the data and can be omitted
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 })
i
是遍历元素的索引。如原生的
map
,forEach
Method.item
为当前项,即当前遍历的元素本身。分别为a
,b
,c
i
为元素处于数组中的下标或索引。分别为0
,1
,2
array
为数组本身。值为['a', 'b', 'c']
i is the index corresponding to the item in the data and can be omitted
Refers to the native map, item is a reference to the data item, i represents the index. i can be omitted
For example:
If it is like the following, arr will be changed