I have 2 arrays.
array1 = [13, 15,18,19, 25]
array2 = [{id:13, label: 'value1'},{id:15,label:'value2'},{id:25, label:'value3'}]
How to check if all the values of array2.id is present in array1?
Iterate over array 2 and check that the id from every element is included in array 1.
array2.every(({ id }) => array1.includes(id));
const array1 = [13, 15, 18, 19, 25];
const array2 = [{
id: 13,
label: 'value1'
}, {
id: 15,
label: 'value2'
}, {
id: 25,
label: 'value3'
}];
const res = array2.every(({ id }) => array1.includes(id));
console.log(res);
const checker = (arr, target) => target.every(({id}) => arr.includes(id)); console.log(checker(array1,array2))