JavaScript 參考手冊
檢測數(shù)組中是否有元素大于 18:
輸出結(jié)果為:
some() 方法用于檢測數(shù)組中的元素是否滿足指定條件(函數(shù)提供)。
some() 方法會依次執(zhí)行數(shù)組的每個元素:
注意: some() 不會對空數(shù)組進(jìn)行檢測。
注意: some() 不會改變原始數(shù)組。
表格中的數(shù)字表示支持該方法的第一個瀏覽器的版本號。
方法 | |||||
---|---|---|---|---|---|
some() | Yes | 9 | 1.5 | Yes | Yes |
array.some(function(currentValue,index,arr),thisValue)
參數(shù) | 描述 | ||||||||
---|---|---|---|---|---|---|---|---|---|
function(currentValue, index,arr) | 必須。函數(shù),數(shù)組中的每個元素都會執(zhí)行這個函數(shù) 函數(shù)參數(shù):
|
||||||||
thisValue | 可選。對象作為該執(zhí)行回調(diào)時(shí)使用,傳遞給函數(shù),用作 "this" 的值。 如果省略了 thisValue ,"this" 的值為 "undefined" |
返回值: | 布爾值。如果數(shù)組中有元素滿足條件返回 true,否則返回 false。 |
---|---|
JavaScript 版本: | 1.6 |
檢測數(shù)組 ages 中是否有元素大于輸入框輸入的值: