- 定义
some( )方法用于监测数组中的元素是否满足指定条件,方法会依次执行数组的每一个元素,如果有一个元素满足条件,表达式返回true,剩余的元素不会再执行监测,如果没有满足条件的元素,则返回false - 注意:
some( )不会对空数组进行监测,不会改变原来的数组 - 语法:
array.some(function( currentVal, index, arr), thisVal)
参数说明:
a. currentVal是必须,指当前元素的值
b. index可选,指当前元素索引值
c. arr可选,指当前元素所属数组对象
d. thisVal可选,对象作为该执行回调时调用,传递给函数,用作this的值,如果省略了·thisVal,this的值是undefined - 例子
var arr = [ 1, 2, 3 ]
if ( arr.some( num =>num < 10 ) ) {
console.log( true )
}
数组的some方法
最新推荐文章于 2024-05-27 12:08:42 发布