foreach()的理解

foreach用于遍历数组中的每一个元素,并将元素传递给回调函数,但对于空数组不会执行回调函数

//语法
array.forEach(function(currentValue, index, arr),thisValue);
forEach有两个参数:
	1. 每个元素需要调用的函数,必选
	2. 非必选
回调函数有三个参数:
	currentValue => 指当前元素,必选
	index => 指当前元素的索引值,非必选
	arr => 指当前数组对象, 非必选 

注意点: 这里的回调函数,通常写为箭头函数
()=>{}

猜你喜欢

转载自blog.csdn.net/zsm4623/article/details/86579001
今日推荐