Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

compare two arrays and return the difference javascript

let difference = arr1
                 .filter(x => !arr2.includes(x))
                 .concat(arr2.filter(x => !arr1.includes(x)));
Comment

compare between two arrays javascript

const equals = (a, b) => JSON.stringify(a) === JSON.stringify(b);
let arr1 = ['1','2'];
let arr2 = ['1','2'];
equals(arr1,arr2)//this return false , if not equal then its return false
Comment

How To Get The Difference Between Two Arrays In JavaScript

function arr_diff (a1, a2) {

    var a = [], diff = [];

    for (var i = 0; i < a1.length; i++) {
        a[a1[i]] = true;
    }

    for (var i = 0; i < a2.length; i++) {
        if (a[a2[i]]) {
            delete a[a2[i]];
        } else {
            a[a2[i]] = true;
        }
    }

    for (var k in a) {
        diff.push(k);
    }

    return diff;
}

console.log(arr_diff(['a', 'b'], ['a', 'b', 'c', 'd']));
console.log(arr_diff("abcd", "abcde"));
console.log(arr_diff("zxc", "zxc"));
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: js display 2d array 
Javascript :: scroll event js 
Javascript :: javascript get random number 
Javascript :: generate thumbnail of pdf using pf js 
Javascript :: queryselector a tag with text 
Javascript :: js filter blur Property 
Javascript :: react save to local storage 
Javascript :: js insert emoji 
Javascript :: map function in react 
Javascript :: TypeError: Object of type uint32 is not JSON serializable 
Javascript :: count number of divs inside a div javascript 
Javascript :: get input type js 
Javascript :: swal con input 
Javascript :: how to use br tag in javascript string 
Javascript :: send data from one page to another html page in Javascript 
Javascript :: view background image in react native 
Javascript :: node js cron example 
Javascript :: getting form values in javascript 
Javascript :: js get random element in array 
Javascript :: print placeholder value js 
Javascript :: like knex 
Javascript :: insert item into array specific index javascript 
Javascript :: btoa javascript 
Javascript :: angular get file from assets 
Javascript :: js escape html 
Javascript :: get element ref react 
Javascript :: Find smallest Number from array in javascript 
Javascript :: sum all elements in array javascript 
Javascript :: remove element from array in usestate 
Javascript :: get combinations of two js 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =