I want a function that returns true if and only if a given array includes all the elements of a given "target" array. As follows.
true
const
You can use .every() and .includes() methods:
.every()
.includes()
let array1 = [1,2,3], array2 = [1,2,3,4], array3 = [1,2]; let checker = (arr, target) => target.every(v => arr.includes(v)); console.log(checker(array2, array1)); console.log(checker(array3, array1));