{"id":7681,"date":"2025-04-10T05:51:43","date_gmt":"2025-04-10T05:51:43","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=7681"},"modified":"2025-05-16T04:11:00","modified_gmt":"2025-05-16T04:11:00","slug":"how-to-get-difference-between-two-arrays-in-javascript","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/","title":{"rendered":"How to Get Difference Between Two Arrays in JavaScript"},"content":{"rendered":"\n<p>JavaScript developers need to commonly work with arrays. They perform numerous operations with them such as <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-append-items-to-js-array\/\">appending items<\/a>, <a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-add-new-elements-to-beginning-of-array-in-javascript\/\">prepending items<\/a>, and so on. While doing so, they need to get the difference between two arrays. There can be various types of differences between arrays, such as checking if they are equal, finding common elements, or getting elements present in one but not the other. Since arrays are reference types of data, it can be difficult for beginners to solve this problem. In this article, we will learn how to difference between two arrays in JavaScript.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#How_to_Get_Difference_Between_Two_Arrays_in_JavaScript\" >How to Get Difference Between Two Arrays in JavaScript<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#1_Using_Equality_Operators\" >1. Using Equality Operators<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#2_Using_JSONstringify\" >2. Using JSON.stringify<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#3_Using_toString\" >3. Using toString<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#4_Using_Every_function\" >4. Using Every() function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#5_Using_for_loop\" >5. Using for loop<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#6_Using_Filter\" >6. Using Filter<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#7_Using_Set\" >7. Using Set<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#8_Using_Lodash\" >8. Using Lodash<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#FAQs\" >FAQs<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Get_Difference_Between_Two_Arrays_in_JavaScript\"><\/span>How to Get Difference Between Two Arrays in JavaScript<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Here are the different ways to get difference between two arrays in JavaScript.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_Equality_Operators\"><\/span>1. Using Equality Operators<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Typically, we use equality operators such as &#8216;==&#8217; or &#8216;===&#8217; to check if two variables are equal or not. Here is an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">a=1;<br>b=1;<br>console.log(a===b); \/\/ output is true<\/pre>\n\n\n\n<p>However, they do not work for arrays, since two arrays have different references even if they contain the same elements.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2, 3];<br>console.log(c===d); \/\/ output is false<br>console.log(c==d); \/\/ output is false<\/pre>\n\n\n\n<p>On the other hand, only if you explicitly assign one variable to another, then you can use this operator to check equality between arrays. This is because in this case, they refer to the same object in memory.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>e=c;<br>console.log(c===e); \/\/ output is true<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_JSONstringify\"><\/span>2. Using JSON.stringify<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this solution, we convert the JavaScript arrays into strings and compare the string representations for equality. For this purpose, we use JSON.stringify() function. If two arrays are identical, their string representations will be identical.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2, 3];<br>console.log(JSON.stringify(c) === JSON.stringify(d)); \/\/ output is true<\/pre>\n\n\n\n<p>This approach works only if your arrays are simple (not nested arrays or arrays with references), and have same order of elements. Even if the arrays have same items in different order this solution will not work.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 3, 2];<br>console.log(JSON.stringify(c) === JSON.stringify(d)); \/\/ output is false<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_toString\"><\/span>3. Using toString<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Similarly, you can also use toString() available for all JS variables and literals. It converts the data into string. In this case, toString() converts array into string, which can then be compared using equality operators.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2,3];<br>console.log(c.toString() === d.toString()); \/\/ output is true<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_Using_Every_function\"><\/span>4. Using Every() function<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this case, we check each pair of items in both arrays at every index. First, you need to check if both arrays have same length.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2, 3];<br>if(c.length==d.length){<br>    console.log(c.every((value, index) =&gt; value === d[index]));<br>}<\/pre>\n\n\n\n<p>In the above code, every() function loops through the first array and for each array item, it checks if the corresponding value of the second array is equal to it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"5_Using_for_loop\"><\/span>5. Using for loop<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Sometimes the array items themselves are complex objects instead of simple data types such as numbers and strings. In such cases, you need to do a recursive comparison. Here is an example.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">function check_equal(a, b) {<br>  if (a.length !== b.length) return false;<br><br>  for (let i = 0; i &lt; a.length; i++) {<br>    const val1 = a[i];<br>    const val2 = b[i];<br><br>    const areObjects = typeof val1 === 'object' &amp;&amp; typeof val2 === 'object';<br>    if (areObjects &amp;&amp; !check_equal(val1, val2)) return false;<br>    if (!areObjects &amp;&amp; val1 !== val2) return false;<br>  }<br>  return true;<br>}<br><br>console.log(check_equal([1, [2, 3]], [1, [2, 3]])); \/\/ Output: true<br>console.log(check_equal([1, [2, 3]], [1, [3, 2]])); \/\/ Output: false<\/pre>\n\n\n\n<p>In the above code, we have defined check_equal recursive function. First, it checks if the lengths of the two arrays are equal. If not, then it returns false. Else it loops through the arrays in parallel, comparing pairs of corresponding items, one pair at a time.<\/p>\n\n\n\n<p>While comparing a pair of items from the two arrays, it checks if the two items are objects. If so, then it recursively calls check_equal function on them too. Its result is used to decide whether the two object items are equal or not.<\/p>\n\n\n\n<p>First it checks if the two items are objects but unequal then return false. If they are not objects and not equal either, then also return false. Otherwise, return true.<\/p>\n\n\n\n<p>Using for loop is one of the most basic ways to check array difference. But it provides the most customization options, as we can see above.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"6_Using_Filter\"><\/span>6. Using Filter<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>JavaScript arrays support filter function that tests each item of an array and returns items that pass the test. You can use it in different ways to compare two arrays.<\/p>\n\n\n\n<p>We will first learn how to use filter function to get common items in two arrays. In other words, we get the intersection of two arrays. JavaScript provides includes function to help you check if an item is present in an array. It returns true if the item is present, else it returns false. We will use this function to get all the common items in two arrays.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[3, 4, 5];<br>console.log(c.filter(el =&gt; d.includes(el)))<\/pre>\n\n\n\n<p>In the above code, we call filter() function on first array. In the filter function that runs for each item of first array, we check if each item is present in second array, using includes() function.<\/p>\n\n\n\n<p>You can also use this same logic to check if the two arrays are equal. If they are equal then the result of filter function is same as either of the two arrays.<\/p>\n\n\n\n<p>There are two ways to calculate difference between two arrays &#8211; symmetric and asymmetric. In symmetric difference, we find the items that are not common to the two arrays. In other words, they are present in either of the two arrays but not in both arrays.<\/p>\n\n\n\n<p>In asymmetric difference, we find the items that are present in one of the arrays but not the other array. <\/p>\n\n\n\n<p>Let us look at both these differences one by one. Here is an example of asymmetric difference. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2, 4];<br><br>console.log(c.filter(el =&gt; !d.includes(el))); \/\/ output is [3]<\/pre>\n\n\n\n<p>In the above code, we call filter function on array c. In this, we test each element of array c to see if it is NOT present in array d. The filter function will return [3] since it is present only in array c.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2, 4];<br><br>console.log(d.filter(el =&gt; !c.includes(el))); \/\/ output is [4]<\/pre>\n\n\n\n<p>In the above code, we interchange c and d, to get items that are present in array d but not in array c. The filter function will return [4] since it is present only in array d.<\/p>\n\n\n\n<p>Here is an example of symmetric difference in two arrays. In the following code, we basically concatenate the result of the above two asymmetric differences, using concat() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">console.log(c.filter(el =&gt; !d.includes(el)).concat(d.filter(el =&gt; !c.includes(el)))); \/\/ output is [3, 4]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"7_Using_Set\"><\/span>7. Using Set<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the previous solutions, the order of array items is important. Even if two arrays have identical items but in different orders then the above solutions will return false. In such cases, you can convert the arrays into sets and compare them. By definition, the order of items does not matter.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2, 4];<br>console.log(new Set(c).size === new Set(d.filter(el =&gt; c.includes(el))).size); \/\/ output is false<br><br>c=[1, 2, 3];<br>d=[3, 1, 2];<br>console.log(new Set(c).size === new Set(d.filter(el =&gt; c.includes(el))).size); \/\/ output is true<\/pre>\n\n\n\n<p>In the above code, we first obtain an array of all items in second array, that are present in first array. For this, we use filter() function. We construct a set using the result array. We also construct another set using the first array. We compare the number of items of both the sets, using their size attributes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"8_Using_Lodash\"><\/span>8. Using Lodash<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/lodash.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Lodash<\/a> is a popular JavaScript library that allows you to work with arrays and other parts of your web data. It contains isEqual() function that allows you to compare two arrays. It is a comprehensive function that even compares objects, references and nested arrays.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const _ = require('lodash');<br><br>console.log(_.isEqual([1, 2, 3], [1, 2, 3])); \/\/ output is true<br>console.log(_.isEqual([1, [2, 3]], [1, [3, 2]])); \/\/ output is false<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt several different ways to get difference between two arrays in JavaScript. If the order of items in two arrays is not the same, then you can convert them into Set and compare them to get the result. If two arrays have same order for most or all items, then you can use toString or JSON.stringify to convert them into strings and comparing the two string representations. If you want to get items present in one array but not the other, then you can calculate asymmetric or symmetric difference, using filter() function.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>1. How to get asymmetric difference between two arrays?<\/strong><\/p>\n\n\n\n<p>You can use filter function for this purpose. Test if each item of one array is present in the other array using includes() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[1, 2, 4];<br><br>console.log(c.filter(el =&gt; !d.includes(el))); \/\/ output is [3]<\/pre>\n\n\n\n<p><strong>2. How to get array difference if the order of items are different in both arrays but they contain same items?<\/strong><\/p>\n\n\n\n<p>In this case, you can convert the arrays into Sets and compare the two sets for equality. Sets contain unique items in unordered manner.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">c=[1, 2, 3];<br>d=[3, 1, 2];<br>console.log(new Set(c).size === new Set(d.filter(el =&gt; c.includes(el))).size); \/\/ output is true<\/pre>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-remove-character-from-string-in-javascript\/\">How to Remove Character from String in JS<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-do-i-replace-all-occurrences-of-a-string-in-javascript\/\">How to Replace All Occurrences of Substring in JS<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-check-whether-string-contains-substring-in-javascript-2\/\">How to Check Whether String Contains Substring in JS<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes web developers need to calculate difference between two arrays in JavaScript. Here are different ways to do this.<\/p>\n","protected":false},"author":1,"featured_media":7710,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[295],"tags":[407],"class_list":["post-7681","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-array-difference"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Get Difference Between Two Arrays in JavaScript - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Sometimes web developers need to calculate difference between two arrays in JavaScript. Here are different ways to do this.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Get Difference Between Two Arrays in JavaScript - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Sometimes web developers need to calculate difference between two arrays in JavaScript. Here are different ways to do this.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-10T05:51:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-16T04:11:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/array-difference-javascript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"312\" \/>\n\t<meta property=\"og:image:height\" content=\"234\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Get Difference Between Two Arrays in JavaScript\",\"datePublished\":\"2025-04-10T05:51:43+00:00\",\"dateModified\":\"2025-05-16T04:11:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/\"},\"wordCount\":1287,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/array-difference-javascript.jpg?fit=312%2C234&ssl=1\",\"keywords\":[\"array difference\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/\",\"name\":\"How to Get Difference Between Two Arrays in JavaScript - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/array-difference-javascript.jpg?fit=312%2C234&ssl=1\",\"datePublished\":\"2025-04-10T05:51:43+00:00\",\"dateModified\":\"2025-05-16T04:11:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Sometimes web developers need to calculate difference between two arrays in JavaScript. Here are different ways to do this.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/array-difference-javascript.jpg?fit=312%2C234&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2025\\\/04\\\/array-difference-javascript.jpg?fit=312%2C234&ssl=1\",\"width\":312,\"height\":234,\"caption\":\"get difference between two arrays in javascript\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-get-difference-between-two-arrays-in-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Get Difference Between Two Arrays in JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Get Difference Between Two Arrays in JavaScript - Ubiq BI","description":"Sometimes web developers need to calculate difference between two arrays in JavaScript. Here are different ways to do this.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Get Difference Between Two Arrays in JavaScript - Ubiq BI","og_description":"Sometimes web developers need to calculate difference between two arrays in JavaScript. Here are different ways to do this.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2025-04-10T05:51:43+00:00","article_modified_time":"2025-05-16T04:11:00+00:00","og_image":[{"width":312,"height":234,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/array-difference-javascript.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Get Difference Between Two Arrays in JavaScript","datePublished":"2025-04-10T05:51:43+00:00","dateModified":"2025-05-16T04:11:00+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/"},"wordCount":1287,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/array-difference-javascript.jpg?fit=312%2C234&ssl=1","keywords":["array difference"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/","name":"How to Get Difference Between Two Arrays in JavaScript - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/array-difference-javascript.jpg?fit=312%2C234&ssl=1","datePublished":"2025-04-10T05:51:43+00:00","dateModified":"2025-05-16T04:11:00+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Sometimes web developers need to calculate difference between two arrays in JavaScript. Here are different ways to do this.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/array-difference-javascript.jpg?fit=312%2C234&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/array-difference-javascript.jpg?fit=312%2C234&ssl=1","width":312,"height":234,"caption":"get difference between two arrays in javascript"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-get-difference-between-two-arrays-in-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Get Difference Between Two Arrays in JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2025\/04\/array-difference-javascript.jpg?fit=312%2C234&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1ZT","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=7681"}],"version-history":[{"count":30,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7681\/revisions"}],"predecessor-version":[{"id":8207,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/7681\/revisions\/8207"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/7710"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=7681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=7681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=7681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}