[Solved] Check if array contains in an object property all elements of another array in js


You can use map and every for this. With map you extract the ids into an array (keys). With every you check if for every element in array2 a condition holds.

let array1 = [
    {id: 123, name: "Name of item"},
    {id: 456, name: "Other name"}
]
let array2 = [123, 456]

const keys = array1.map(el => el.id)
console.log(array2.every(id => keys.includes(id)))

1

solved Check if array contains in an object property all elements of another array in js