前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数组过滤总结

数组过滤总结

作者头像
杭州前端工程师
发布2018-06-15 11:59:10
9470
发布2018-06-15 11:59:10
举报
文章被收录于专栏:前端大白专栏前端大白专栏

第一种:

代码语言:javascript
复制
var arr = [
    {appid: '7e2702c3', status: 0},
    {appid: 'ad02cfe0', status: 1},
    {appid: '5a64af02', status: 2}
];

var newArr = arr
    .filter(item => item.status === 2)
    .map(item => item.appid);

console.log(newArr);//[ '5a64af02' ]

第二种:

代码语言:javascript
复制
var arr = [ 
    {'appid':'7e2702c3','status':0},
    {'appid':'ad02cfe0','status':1},
    {'appid':'5a64af02','status':2}
];
arr.find(i => i.status == 2).appid;

第三种:

代码语言:javascript
复制
var arr = [ 
    {'appid':'7e2702c3','status':0},
    {'appid':'ad02cfe0','status':1},
    {'appid':'5a64af02','status':2}
];
arr.reduce((res,term) => term.status == 2 ? res.concat(term) : res,[])

第四种:

代码语言:javascript
复制
var arr = [ 
        {'appid':'7e2702c3','status':0},
        {'appid':'ad02cfe0','status':1},
        {'appid':'5a64af02','status':2}
    ],
    newArr = [];

arr.map(function(n) {
    if(n.status === 2) {
        newArr.push(n.appid);
    }
})
console.log(newArr);

以上方式来自网络,有兴趣的可以自己云验证一下是否可行!

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档