How to useJavaScript array.some() method in Javascript
This approach declares false if some element of the second array is not present in the first array.
Example: This example uses the approach discussed above.
Javascript
// Create input arrays let arr1 = [ "GFG" , "Geeks" , "Portal" , "Geek" , "GFG_1" , "GFG_2" ]; let arr2 = [ "GFG" , "Geeks" , "GeekForGeeks" ]; // Function to check subarrays function GFG_Fun() { let res = !arr2.some(val => arr1.indexOf(val) === -1); let not = "" ; if (!res) { not = "not" ; } // Display output console.log( "Array_2 is " + not + " the subset of Array_1" ); } GFG_Fun(); |
Output
Array_2 is not the subset of Array_1
How to check whether an array is subset of another array using JavaScript ?
The task is to check whether an array is a subset of another array with the help of JavaScript. There are a few approaches, we will discuss below: