foreach :
[ ].forEach(function(value,index,array){
//code something
});
//forEach()方法对数组的每个元素执行一次提供的函数。
//forEach方法中的function回调有三个参数:
//第一个参数是遍历的数组内容,
//第二个参数是对应的数组索引,
//第三个参数是数组本身
//forEach不支持break,会报错
//forEach中使用return无效,但不会报错
//如果要用return返回某个值,那就只能将return操作放在函数中,而不是forEach循环中,像这样:
function find(array, num) {
let _index;
array.forEach((self, index) => {
if (self === num) {
_index = index;
};
});
return _index;
};