Array.some()方法
语法
array.some(function(currentValue,index,arr),thisValue)
currentValue
:必选。当前元素。index
:可选。当前元素索引值。arr
:可选。当前元素所属的数组对象。thisValue
:可选。传递给函数,用作“this”的值;如果省略,"this"值则为"undefined"
参数分解:
const arr = [3,4,5,6,7,8]arr.some(function (currentValue,index,arr) {
console.log(currentValue);
})
复制代码
const arr = [3,4,5,6,7,8]
arr.some(function (currentValue,index,arr) {
console.log(index);
})
复制代码
const arr = [3,4,5,6,7,8]
arr.some(function (currentValue,index,arr) {
console.log(arr);
})
复制代码
用途
遍历数组中每个元素,判断其是否满足指定函数的指定条件,返回true或者false
- 如果一个元素满足条件,返回true,且后面的元素不再被检测
- 所有元素都不满足条件,则返回false
- 不会改变原始数组
- 不会对空数组进行检测;数组为空的话,直接返回false
实例
检测数组中是否有值满足函数指定的条件
const arr = [4, 12, 16, 20];arr.some(item => {item > 18
})
//true
复制代码
Array.some()方法相关推荐
- JS Array filter()方法
JS Array filter()方法 js的数据对象有一个fileter()方法,运行传入一个方法,并对数组中的每个元素进行过滤. var arr = [1,2,3,4,5,6]; function ...
- ruby array_Ruby中带有示例的Array.select方法
ruby array Array.select方法 (Array.select Method) In the last articles, we have seen how to iterate ov ...
- ruby中、.reject_Ruby中带有示例的Array.reject方法
ruby中..reject Ruby Array.reject方法 (Ruby Array.reject Method) In the last article, we have seen how w ...
- ruby array_Ruby中带有示例的Array.shuffle方法
ruby array Array.shuffle方法 (Array.shuffle Method) In this article, we will study about Array.shuffle ...
- ruby array_在Ruby中使用Array.pop和Array.shift方法从Array中删除元素
ruby array Ruby Array.pop和Array.shift方法 (Ruby Array.pop and Array.shift methods) If you are reading ...
- _.uniq_在Ruby中使用Array.compact和Array.uniq方法从Array中移除元素
_.uniq Ruby Array.compact和Array.uniq方法 (Ruby Array.compact and Array.uniq Methods) In the last artic ...
- ruby .each_Ruby中带有示例的Array.each方法
ruby .each Ruby Array.each方法 (Ruby Array.each method) Array.each method can be easily termed as a me ...
- ruby array_Ruby中带有示例的Array.keep_if方法
ruby array Ruby Array.keep_if方法 (Ruby Array.keep_if Method) In the last articles, we have studied th ...
- ruby array_Ruby中带有示例的Array.delete_if方法
ruby array Ruby Array.delete_if方法 (Ruby Array.delete_if Method) In the last articles, we have studie ...
- python创建数组的方法_numpy创建array的方法汇总
创建numpy.array,是使用numpy这个核武器的基础,本文尽量汇总常用创建numpy.array的方法. array函数 >>> import numpy as np > ...
最新文章
- ASP.NET遍历配置文件的连接字符串
- Mac中安装JDK1.8和JDK11双版本并任意切换
- Oracle10g数据库归档与非归档模式下的备份与恢复
- __METHOD__
- STL源码剖析 heap堆结构
- Dynamo论文导读
- selenium python自动化测试 ddt数据驱动
- 5星评价,1位小数显示
- everything软件使用技巧
- 读《About Face 4 交互设计精髓》7
- 逆水寒ol服务器维修,逆水寒OL:官方再开多个服务器玩家关心的问题却是一个字_...
- 怎样查找计算机的ip mac地址,如何通过mac地址查ip,教您Mac怎么查看ip地址
- 金杉号:2022什么工作最赚钱,未来十年最吃香的4个稳定的工作
- Python爬取文章和小说内容
- 这样可以几分钟快速对接支付宝APP支付和手机网站支付
- 2021-01-11小米随身wifi网络创建总是失败是什么问题?
- 程序员遇到人生低谷期怎么做?
- linux库怎么安装路径设置,Linux libtins 库安装教程
- SQL:统计每5min在线人数思路
- Facebook时间序列预测算法模型-prophet