js中的map()、some()、every()、filter()

map():通过指定函数处理数组的每个元素,并返回处理后的数组,其结果是该数组中的每个元素都调用一个提供的函数后返回的结果
语法:array.map(function(currentValue, index, arr), thisValue)
参数说明:
currentValue: 必须,当前元素的值;
index:可选,当前元素的索引值;
arr:可选,当前元素所属的数组;
thisValue:可选,传递给函数的值一般用作 “this” 值。如果省略了 thisValue ,“this” 的值为 “window”。
注意:map不会改变原数组,map不会检查空数组
demo:
js中的map()、some()、every()、filter()
js中的map()、some()、every()、filter()
some():是对数组中每一项运行给定函数,如果该函数对任一项返回true,则返回true。
语法:array.some(function(currentValue, index, arr), thisValue)
参数说明:
currentValue: 必须,当前元素的值;
index:可选,当前元素的索引值;
arr:可选,当前元素所属的数组;
thisValue:可选,传递给函数的值一般用作 “this” 值。如果省略了 thisValue ,“this” 的值为 “window”
注意: some() 不会对空数组进行检测。
注意: some() 不会改变原始数组。
demo:
js中的map()、some()、every()、filter()

every:是对数组中每一项运行给定函数,如果该函数对每一项返回true,则返回true。
参数同some一样。
注意: every() 不会对空数组进行检测。
注意: every() 不会改变原始数组。
demo:
js中的map()、some()、every()、filter()

filter:创建一个新的数组,新数组中的元素是通过检查指定数组中符合条件的所有元素
参数同some一样
注意: filter() 不会对空数组进行检测。
注意: filter() 不会改变原始数组。
demo:
js中的map()、some()、every()、filter()