js数组取对象
数组取对象
var arr1 = [
{ id: "1", name: "one", age: "one" },
{ id: "2", name: "two", age: "two" },
{ id: "3", name: "three", age: "three" },
{ id: "4", name: "four", age: "four" },
{ id: "5", name: "five", age: "five" },
{ id: "6", name: "sex", age: "sex" },
{ id: "7", name: "qi", age: "qi" }
];
var arr2 = [1, 3, 5, 7];
var arr = [];
for (var i = 0; i < arr2.length; i++) {
for (var j = 0; j < arr1.length; j++) {
if (arr2[i] == parseInt(arr1[j].id)) {
let param = {
id: arr1[j].id,
name: arr1[j].name
};
arr.push(param);
}
}
}