How to check whether an array is subset of another array using JavaScript ? Last Updated : 13 Jul, 2023 Comments Improve Suggest changes Like Article Like Report 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: Approaches:using JavaScript array.every() methodusing JavaScript array.some() methodApproach 1: Using JavaScript array.every() methodThis approach checks whether every element of the second array is present in the first array or not. Example: This example uses the approach discussed above. JavaScript // Creating 2 arrays let arr1 = ["GFG", "Geeks", "Portal", "Geek", "GFG_1", "GFG_2"]; let arr2 = ["GFG", "Geeks", "Geek"]; // Funtion to check subarray function GFG_Fun() { let res = arr2.every(function (val) { return arr1.indexOf(val) >= 0; }); let not = ""; if (!res) { not = "not"; } // Display the output console.log("Array_2 is " + not + " the subset of Array_1"); } GFG_Fun(); OutputArray_2 is the subset of Array_1 Approach 2: Using JavaScript array.some() methodThis 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(); OutputArray_2 is not the subset of Array_1 Comment More infoAdvertise with us Next Article How to check whether an array is subset of another array using JavaScript ? P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies subset javascript-array JavaScript-DSA JavaScript-Questions +2 More Practice Tags : subset Similar Reads Find whether an array is subset of another array using Map Given two arrays: arr1[0..m-1] and arr2[0..n-1]. Find whether arr2[] is a subset of arr1[] or not. Both the arrays are not in sorted order. It may be assumed that elements in both arrays are distinct.Examples: Input: arr1[] = {11, 1, 13, 21, 3, 7}, arr2[] = {11, 3, 7, 1} Output: arr2[] is a subset o 7 min read How to get the elements of one array which are not present in another array using JavaScript? The task is to get the elements of one array that are not present in another array. Here we are going to use JavaScript to achieve the goal. Here are a few techniques discussed. Approach Take the arrays in variables.Use the .filter() method on the first array and check if the elements of the first a 2 min read How to Create an Array using Intersection of two Arrays in JavaScript ? In this article, we will try to understand how to create an array using the intersection values of two arrays in JavaScript using some coding examples. For Example: arr1 = [1, 3, 5, 7, 9, 10, 14, 15]arr2 = [1, 2, 3, 7, 10, 11, 13, 14]result_arr = [1, 3, 7, 10, 14]Approach 1: We will see the native a 3 min read How to check whether an array includes a particular value or not in JavaScript ? In this article, we will discuss the construction of an array followed by checking whether any particular value which is required by the user is included (or present) in the array or not. But let us first see how we could create an array in JavaScript using the following syntax- Syntax: The followin 3 min read How to Check Object is an Array in JavaScript? There are two different approaches to check an object is an array or not in JavaScript.1. Using Array.isArray() MethodThe Array.isArray() method determines whether the value passed to this function is an array or not. This method returns true if the argument passed is an array else it returns false. 1 min read How to check if an array includes an object in JavaScript ? Check if an array includes an object in JavaScript, which refers to determining whether a specific object is present within an array. Since objects are compared by reference, various methods are used to identify if an object with matching properties exists in the array.How to check if an array inclu 3 min read How to Filter an Array from all Elements of another Array In JavaScript? Filtering one array from all elements of another array is a common task in JavaScript. This involves removing elements from one array that are present in another array. In this article we will explore different approaches to filter an array from all elements of another array in JavaScript.These are 4 min read How to check an Array Contains an Object of Attribute with Given Value in JavaScript ? Sometimes, when working with an array of objects in JavaScript, we need to determine whether an object with a specific attribute value exists in the array. This can be useful when filtering or searching for specific objects in the array. Below are the common methods to determine if the array contain 4 min read How to Check if a Variable is an Array in JavaScript? To check if a variable is an array, we can use the JavaScript isArray() method. It is a very basic method to check a variable is an array or not. Checking if a variable is an array in JavaScript is essential for accurately handling data, as arrays have unique behaviors and methods. Using JavaScript 2 min read JavaScript - Match Values from Another Array and Assign to Object of Arrays Here are the different methods to match values from another array and assign to object of arrays in JavaScript1. Using forEach() and push()In this method, we will be using the forEach() and push() methods of the array to get the same value from another array and assign it to the object of arrays.Jav 3 min read Like