这几天刚好用到了这个知识点,就记录一下 ,方便查阅
let arrObj = [
{name:'半夏',age:22},{name:'满冬',age:25}
]
//检查name是否有满冬
let isHasMandong = arrObj.some(obj => obj.name === '满冬');
console.log(isHasMandong);//true
顺便记录下,数组是否包含元素
let array = [1, 2, 3, 4, 5];
// 检查元素是否在数组中
let elementToCheck = 3;
let isElementInArray = array.includes(elementToCheck);
console.log(isElementInArray); // 输出: true
const arr1 = [1,2,3,4,5];
const arr2 = [2,3];
//arr1 去除arr2里面的元素
const newArr = arr1.filter(item=>!arr2.includes(item))
console.log(newArr);//【1,4,5】
.数组去重
const arr1 = [1,2,3,4,5];
const arr2 = [2,3,6,9];
//arr1 去除arr2里面的元素
const newArr = [...new Set(arr1.concat(arr2))]
console.log(newArr);//【1,2,3,4,5,6,9】