javascript - I would like to ask, what does i in _map(data,(item,i)=>{}) and _each(data,(item,i)=>{}) do?
世界只因有你
世界只因有你 2017-05-16 13:39:53
0
3
552

Like the title, can you not write it

世界只因有你
世界只因有你

reply all(3)
phpcn_u1582

i是遍历元素的索引。
如原生的mapforEachMethod.

['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']

洪涛

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
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template