当前位置:网站首页>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
边栏推荐
- uniapp引入本地字体
- Latex error: the font size command \normalsize is not defined problem solved
- Linux MySQL 5.6.51 community generic installation tutorial
- CTF web practice competition
- JS modification element attribute flipping commonly used in selenium's Web Automation
- Atcoder beginer contest 253 F - operations on a matrix / / tree array
- Vector types and variables built in CUDA
- Render minecraft scenes into real scenes using NVIDIA GPU
- CUDA user object
- How to try catch statements that return promise objects in JS
猜你喜欢
Detailed definition of tensorrt data format
[Zhang San learns C language] - deeply understand data storage
Stack (linear structure)
Latex error: the font size command \normalsize is not defined problem solved
Explanation and application of annotation and reflection
uniapp引入本地字体
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)
In depth study of JVM bottom layer (IV): class file structure
Sentinel rules persist to Nacos
AWD学习
随机推荐
Stack (linear structure)
CTF web practice competition
VSCODE 安装LATEX环境,参数配置,常见问题解决
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
如何调试微信内置浏览器应用(企业号、公众号、订阅号)
PgSQL learning notes
A preliminary study on ant group G6
pytest(1) 用例收集规则
unittest. Texttestrunner does not generate TXT test reports
selenium备忘录:selenium\webdriver\remote\remote_connection.py:374: ResourceWarning: unclosed<xxxx>解决办法
No process runs when querying GPU, but the video memory is occupied
Deployment API_ automation_ Problems encountered during test
Sentinel Alibaba open source traffic protection component
Storage space modifier in CUDA
CUDA and Direct3D consistency
There are multiple good constructors and room will problem
Latex warning: citation "*****" on page y undefined on input line*
Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
In depth study of JVM bottom layer (IV): class file structure
Win电脑截图黑屏解决办法