A数组:

var aa = [
    {name:'Anne', age: 23, gender:'female'},
    {name:'Leila', age: 16, gender:'female'},
    {name:'Jay', age: 19, gender:'male'},
    {name:'Mark', age: 40, gender:'male'}
]

一、筛选出Jay的资料:  用filter方法,判断name是否为目标名字即可

console.log(aa.filter(item=>item.name==='Jay'));
//[{…}]
//0: {name: "Jay", age: 19, gender: "male"}
//length: 1
//__proto__: Array(0)

二、筛选出Jay、Mark的资料:用for循环遍历目标数组,然后用find方法找到后push到结果数组里

 let bb=['Jay','Mark']
 let result = []
    for(let i = 0; i < bb.length; i++) {

        result.push(aa.find(item => item.name = bb[i]))
    }

//输出为 [{name:'Anne', age: 23, gender:'female'},{name:'Jay', age: 19, gender:'male'}]

三、筛选出Jay或者23岁的资料:用filter方法,判断条件之间是或的关系。

aa.filter(item => item.name == 'Jay' || item.age == 23)

 

 posted on 2020-11-30 18:24  楼顶铁板烧  阅读(66)  评论(0编辑  收藏  举报