js两个数组进行数据筛选
2019-06-20 本文已影响0人
回不去的那些时光
原理:使用两个for循环进行循环判断
var list = [
{ code: 101, name: "aa" },
{ code: 103, name: "bb" },
{ code: 1001, name: "cc" },
{ code: 1011, name: "cc" }];
var list1 = [
{ name: "dj", age: 1001 },
{ name: "zs", age: 1011 },
{ name: "ww", age: 101 },
{ name: "wj", age: 103 }];
var list2 = [];
list.forEach(val => {
let aa = list1.find(value => {
return value.age == val.code;
})
list2.push(aa);
})
console.log(list2);