一个数组包含另一个数组
let arr1 = [1,2,3]
let arr2 = [1,2,3,4,5]
function contains(arr1,arr2){
for(let i of arr1) {
if(!arr2.includes(i)) { false }
}
return true
}
console.log(contains(arr1,arr2)) // true
两个数组对象属性合并
const list = [
{ x: 10, y: 10 },
{ x: 11, y: 11 },
{ x: 9, y: 9 },
{ x: 12, y: 12 },
];
const arr = [
{
name: "章三",
value: 1,
},
{
name: "李四",
value: 2,
},
{
name: "王五",
value: 3,
},
];
arr.map((item,index) => {
return {
...item,
...list[index]
}
})