Thursday 21 October 2021

JavaScript = Check if array contains at least one element of another array

 https://stackoverflow.com/questions/16312528/check-if-an-array-contains-any-element-of-another-array-in-javascript

    // Check if arra1 contains at least 1 element of arr2

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

some(..) checks each element of the array against a test function and returns true if any element of the array passes the test function, otherwise, it returns false. indexOf(..) >= 0 and

No comments:

Post a Comment