some:array.some(function(currentValue,index,arr),thisValue)
检测数组中的数据,如果有一项为真就返后true,否则返回false
every:array.some(function(currentValue,index,arr),thisValue)
检测数组中是否满足要求,会依次执行数组中每一个元素,如果每一个满足条件就返回true,否则返回false;
注意:如果是空数组,返回值也为true
find:array.find(function(currentValue, index, arr),thisValue)
返回通过测试的第一个值(是返回值哈)
findIndex:array.findIndex(function(currentValue, index, arr), thisValue)
返回的是满足条件的第一个元素的索引值 - index
includes:arr.includes(searchElement)
可以检测数组和字符串,如果包含则返回ture,否则返回false!
filter:arr.filter(item => {}):
返回一个满足条件的新数组,不会改变原数组,筛选不到则返回空数组
map:arr.map(item => {})
也是循环遍历数组,返回值是一个新数组,作用是对原数组元素进行处理,不会改变原数组
forEach:array.forEach(function(currentValue, index, arr), thisValue)
没有返回值,本质上等同于 for 循环,对每一项执行 function 函数,改变原数组
for:for(let i = 0;i<arr.length;i++){}
这种方式是最传统的遍历方式,性能原则上是最好的
for…in:for(key in obj){}
这种方式一般用来遍历对象,但是确实是能够遍历数组的,只不过一般人很少会这么做,性能偏低
for…of:for(item of arr) {}
此种遍历方式简洁方便,可以用来遍历数组、类数组对象,字符串、Set、Map 以及 Generator 对象