当前位置:网站首页>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 true
2.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
边栏推荐
- Build learning tensorflow
- In depth study of JVM bottom layer (V): class loading mechanism
- Latex compilation error I found no \bibstyle &\bibdata &\citation command
- Dynamic global memory allocation and operation in CUDA
- How to try catch statements that return promise objects in JS
- Eggjs -typeorm treeenity practice
- Automation - when Jenkins pipline executes the nodejs command, it prompts node: command not found
- Fe - use of weex development weex UI components and configuration use
- Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
- Detailed definition of tensorrt data format
猜你喜欢
Latex compiles Chinese in vscode and solves the problem of using Chinese path
CTF three count
Apt command reports certificate error certificate verification failed: the certificate is not trusted
AWD learning
js中对于返回Promise对象的语句如何try catch
sqli-labs通关汇总-page3
Vscode installation, latex environment, parameter configuration, common problem solving
如何调试微信内置浏览器应用(企业号、公众号、订阅号)
Sublime text configuring PHP compilation environment
How to debug wechat built-in browser applications (enterprise number, official account, subscription number)
随机推荐
20201025 visual studio2019 qt5.14 use of signal and slot functions
Vscode installation, latex environment, parameter configuration, common problem solving
Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
Pytest (3) parameterize
Browser scrolling for more implementations
Alibaba cloud MFA binding Chrome browser
Asynchronous data copy in CUDA
ZZQ的博客目录--更新于20210601
NodeJs - Express 中间件修改 Header: TypeError [ERR_INVALID_CHAR]: Invalid character in header content
Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决
Virtualenv and pipenv installation
Win10: add or delete boot items, and add user-defined boot files to boot items
Improve user experience defensive programming
Latex在VSCODE中编译中文,使用中文路径问题解决
web自动化切换窗口时报错“list“ object is not callable
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
Explanation and application of annotation and reflection
Record RDS troubleshooting once -- RDS capacity increases dramatically
Latex compilation error I found no \bibstyle &\bibdata &\citation command
Win电脑截图黑屏解决办法