js里面forEach()的用法:
1、react里面的用法:
var arr = [];
this.props.aa.forEach(function (i,index) {
arr.push(
<p>{i}</p>
)
})
2、首先定义一个数组
var arr=['a','b',12];
//当js的forEach方法的匿名函数参数列表只有一个时,代表的是数组的元素值
arr.forEach(function(item){console.log(item); });
输出:
a
b
12
//当js的forEach方法的匿名函数参数列表有两个时,前者代表的是数组的元素值,后者代表的是索引;
arr.forEach(function(item,index){console.log(index+'-'+item); });
输出:
0-a
1-b
2-12