check if array exists in another array javascript 1

check if array exists in another array javascript

const found = arr1.some(r=> arr2.includes(r))

Here is what the above code is Doing:
1. We’re using the some() method to check if any of the elements in arr1 pass the test implemented by the callback function.
2. The callback function uses the includes() method to check if the current element is included in arr2.
3. If the current element is included in arr2, the callback function returns true, which some() will use to determine that at least one element in arr1 exists in arr2.
4. If the current element is not included in arr2, the callback function returns false, which some() will use to determine that no elements in arr1 exist in arr2.

Similar Posts