js的常用数组操作

1、判断数组 b 的所有元素是否都在数组 a 中

const a = [1, 2, 3, 4, 5];
const b = [2, 4];

const allElementsInA = b.every(element => a.includes(element));

console.log(allElementsInA); // 输出 true

2、提取对象数组中,某个字段所有 === 某个值的所有数据(如下获取所有关于)

let fiterArr = array.filter(item => Number(item.id) === Number(id))

  

posted @ 2023-11-01 16:38  iwen1992  阅读(1)  评论(0编辑  收藏  举报