定義和用法:
some() 方法用於檢測數組中的元素是否知足指定條件(函數提供)。數組
some() 方法會依次執行數組的每一個元素:函數
若是有一個元素知足條件,則表達式返回true , 剩餘的元素不會再執行檢測。
若是沒有知足條件的元素,則返回false。
注意: some() 不會對空數組進行檢測。this
注意: some() 不會改變原始數組。.net
語法:對象
array.some(function(currentValue,index,arr),thisValue)
參數說明
參數 描述
function(currentValue, index,arr) 必須。函數,數組中的每一個元素都會執行這個函數
函數參數:
參數 描述
currentValue 必須。當前元素的值
index 可選。當前元素的索引值
arr 可選。當前元素屬於的數組對象
thisValue 可選。對象做爲該執行回調時使用,傳遞給函數,用做 "this" 的值。
若是省略了 thisValue ,"this" 的值爲 "undefined"blog
實例說明:索引
var ages = [23,44,3]
if (ages.some(age => age < 10)) {
console.log('true')
}
---------------------
做者:沙子揉碎在眼睛裏
來源:CSDN
原文:https://blog.csdn.net/wh13267207590/article/details/80967216 io