当前位置:网站首页>js判断数组中对象是否存在某个值
js判断数组中对象是否存在某个值
2022-07-02 06:23:00 【xuefankang】
1.some()方法
满足条件返回true,否则返回 false。
var arr = [{
name: "张三",
age: "20"
}, {
name: "李四",
age: "21"
}]
var res = arr.some(function(item) {
if (item.name == "李四") {
return true;
}
})
console.log(res); // 返回true
2.find() 方法
满足条件返回当前对象,否则返回 undefined。
var arr = [{
name: "张三",
age: "20"
}, {
name: "李四",
age: "21"
}]
var res = arr.find((v) => {
return v.age=== '20';
});
console.log(res); // 返回 {name: "张三",age: "20"}
3.findIndex()方法
满足条件的该元素的索引值,否则返回-1。
var arr = [{
name: "张三",
age: "20"
}, {
name: "小鲁班",
age: "21"
}]
var res = arr.findIndex((v) => {
return v.age=== '20';
});
console.log(res); // 返回0
边栏推荐
- Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
- js中对于返回Promise对象的语句如何try catch
- Thread hierarchy in CUDA
- Eggjs -typeorm treeenity practice
- JS modification element attribute flipping commonly used in selenium's Web Automation
- Usage of map and foreach in JS
- [literature reading and thought notes 13] unprocessing images for learned raw denoising
- Fe - wechat applet - Bluetooth ble development research and use
- 【文献阅读与想法笔记13】 Unprocessing Images for Learned Raw Denoising
- After reading useful blogs
猜你喜欢
Shardingsphere JDBC
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
js中map和forEach的用法
Build learning tensorflow
Redis - cluster data distribution algorithm & hash slot
Self study table Au
Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
No process runs when querying GPU, but the video memory is occupied
uniapp引入本地字体
构建学习tensorflow
随机推荐
PIP install
ZZQ的博客目录--更新于20210601
sprintf_ How to use s
Linux MySQL 5.6.51 Community Generic 安装教程
Eslint configuration code auto format
Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
Win电脑截图黑屏解决办法
JS modification element attribute flipping commonly used in selenium's Web Automation
CUDA and Direct3D consistency
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
web自动中利用win32上传附件
Asynchronous data copy in CUDA
CUDA user object
virtualenv和pipenv安装
Selenium+msedgedriver+edge browser installation driver pit
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
js的防抖和节流
Utilisation de la carte et de foreach dans JS
Fe - eggjs combined with typeorm cannot connect to the database