当前位置:网站首页>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边栏推荐
- Improve user experience defensive programming
- 20201025 Visual Studio2019 QT5.14 信号和槽功能的使用
- unittest.TextTestRunner不生成txt测试报告
- Render minecraft scenes into real scenes using NVIDIA GPU
- Code execution sequence with and without resolve in promise
- Pytest (1) case collection rules
- js把一个数组分割成每三个一组
- Record RDS troubleshooting once -- RDS capacity increases dramatically
- js判断数组中对象是否存在某个值
- Android - Kotlin 下使用 Room 遇到 There are multiple good constructors and Room will ... 问题
猜你喜欢

Linux MySQL 5.6.51 community generic installation tutorial

unittest. Texttestrunner does not generate TXT test reports

flex九宫格布局

Apt command reports certificate error certificate verification failed: the certificate is not trusted

js中map和forEach的用法

Stack (linear structure)

Pytest (1) case collection rules

AWD学习

Blog directory of zzq -- updated on 20210601

Sublime text configuring PHP compilation environment
随机推荐
Apt command reports certificate error certificate verification failed: the certificate is not trusted
Linux MySQL 5.6.51 community generic installation tutorial
Virtualenv and pipenv installation
PgSQL learning notes
Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决
浏览器滚动加载更多实现
20210306 reprint how to make TextEdit have background pictures
如何调试微信内置浏览器应用(企业号、公众号、订阅号)
Code execution sequence with and without resolve in promise
微信小程序基础
Huawei mindspire open source internship machine test questions
Latex在VSCODE中编译中文,使用中文路径问题解决
The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem
The table component specifies the concatenation parallel method
Storage space modifier in CUDA
Dynamic global memory allocation and operation in CUDA
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
Warp shuffle in CUDA
Vscode installation, latex environment, parameter configuration, common problem solving