1.提取数组中元素某一属性的值并生成新的数组
eg: let arr1 = [
{a: 1, b: 2},
{a: 11, b: 22}
];
let arr2 = arr1.map(a => a.a);
console.log(arr2); // [1, 11]
2.两个数组获取交集
eg: let arr1 = [1, 2, 3],arr2 = [2, 6, 0];
let intersection = arr1.filter(function (val) {
return arr2.indexOf(val) > -1;
})
console.log(intersection); //[2]
网友评论