当前位置:网站首页>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
边栏推荐
- Atcoder beginer contest 253 F - operations on a matrix / / tree array
- [self cultivation of programmers] - Reflection on job hunting Part II
- 由于不正常断电导致的unexpected inconsistency;RUN fsck MANUALLY问题已解决
- kali最新更新指南
- Tensorrt command line program
- There are multiple good constructors and room will problem
- unittest.TextTestRunner不生成txt测试报告
- 由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
- Fe - weex uses a simple encapsulated data loading plug-in as the global loading method
- Utilisation de la carte et de foreach dans JS
猜你喜欢
unittest. Texttestrunner does not generate TXT test reports
Sentinel rules persist to Nacos
华为MindSpore开源实习机试题
Alibaba cloud MFA binding Chrome browser
Idea announced a new default UI, which is too refreshing (including the application link)
Vscode installation, latex environment, parameter configuration, common problem solving
Code skills - Controller Parameter annotation @requestparam
Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
Pytest (2) mark function
The intern left a big hole when he ran away and made two online problems, which made me miserable
随机推荐
sprintf_ How to use s
Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
压力测试修改解决方案
FE - Eggjs 结合 Typeorm 出现连接不了数据库
Asynchronous data copy in CUDA
部署api_automation_test过程中遇到的问题
重载全局和成员new/delete
Latex compilation error I found no \bibstyle &\bibdata &\citation command
web自动中利用win32上传附件
蚂蚁集团g6初探
Win10桌面图标没有办法拖动(可以选中可以打开可以删除新建等操作但是不能拖动)
华为MindSpore开源实习机试题
selenium备忘录:selenium\webdriver\remote\remote_connection.py:374: ResourceWarning: unclosed<xxxx>解决办法
Selenium+msedgedriver+edge browser installation driver pit
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)
奇葩pip install
Solution to the black screen of win computer screenshot
DeprecationWarning: .ix is deprecated. Please use.loc for label based indexing or.iloc for positi
Huawei mindspire open source internship machine test questions
Flask-Migrate 检测不到db.string() 等长度变化