当前位置:网站首页>JS to determine whether there is a value in the object in the array
JS to determine whether there is a value in the object in the array
2022-07-02 06:50:00 【xuefankang】
1.some() Method
Return... If conditions are met true, Otherwise return to false.
var arr = [{
name: " Zhang San ",
age: "20"
}, {
name: " Li Si ",
age: "21"
}]
var res = arr.some(function(item) {
if (item.name == " Li Si ") {
return true;
}
})
console.log(res); // return true2.find() Method
Return the current object if the condition is met , Otherwise return to undefined.
var arr = [{
name: " Zhang San ",
age: "20"
}, {
name: " Li Si ",
age: "21"
}]
var res = arr.find((v) => {
return v.age=== '20';
});
console.log(res); // return {name: " Zhang San ",age: "20"}3.findIndex() Method
The index value of the element that meets the condition , Otherwise return to -1.
var arr = [{
name: " Zhang San ",
age: "20"
}, {
name: " Little Luban ",
age: "21"
}]
var res = arr.findIndex((v) => {
return v.age=== '20';
});
console.log(res); // return 0边栏推荐
- Atcoder beginer contest 253 F - operations on a matrix / / tree array
- pytest(2) mark功能
- apt命令报证书错误 Certificate verification failed: The certificate is NOT trusted
- 如何调试微信内置浏览器应用(企业号、公众号、订阅号)
- Latex error: the font size command \normalsize is not defined problem solved
- Improve user experience defensive programming
- table 组件指定列合并行方法
- Eggjs -typeorm 之 TreeEntity 实战
- Storage space modifier in CUDA
- In depth study of JVM bottom layer (V): class loading mechanism
猜你喜欢

Sentinel Alibaba open source traffic protection component

There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)

Alibaba cloud MFA binding Chrome browser

Latex warning: citation "*****" on page y undefined on input line*

unittest.TextTestRunner不生成txt测试报告

Self study table Au

解决微信小程序swiper组件bindchange事件抖动问题

Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *

CVE-2015-1635(MS15-034 )远程代码执行漏洞复现

The use of regular expressions in JS
随机推荐
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
Log - 7 - record a major error in missing documents (A4 paper)
The table component specifies the concatenation parallel method
Code execution sequence with and without resolve in promise
2020-9-23 QT的定时器Qtimer类的使用。
Sentinel rules persist to Nacos
js中map和forEach的用法
Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
Kotlin - 验证时间格式是否是 yyyy-MM-dd HH:mm:ss
Self cultivation of programmers - Reflection on job hunting
微信小程序基础
Improve user experience defensive programming
Linux MySQL 5.6.51 Community Generic 安装教程
NodeJs - Express 中间件修改 Header: TypeError [ERR_INVALID_CHAR]: Invalid character in header content
js判断数组中对象是否存在某个值
20201025 Visual Studio2019 QT5.14 信号和槽功能的使用
看完有用的blog
Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
Virtualenv and pipenv installation
js的防抖和节流