Answers for "when are 2 arrays same value in javascript"

2

check if 2 arrays are equal javascript

const a = [1, 2, 3];
const b = [4, 5, 6];
const c = [1, 2, 3];

function arrayEquals(a, b) {
  return Array.isArray(a) &&
    Array.isArray(b) &&
    a.length === b.length &&
    a.every((val, index) => val === b[index]);
}

arrayEquals(a, b); // false
arrayEquals(a, c); // true
Posted by: Guest on February-04-2021
1

when are 2 arrays same value in javascript

// the answer when the index is not important
function arrSimilar(arr1, arr2) {

    // first lets check if the length is the same
    if (arr1.length !== arr2.length) {return false} 
    let notSimilarItemsCounter = 0
    arr1.map((item) => {
        !arr2.includes(item) ? notSimilarItemsCounter++ : true ;
    })
    if ( notSimilarItemsCounter ) {
        return false
    }else {return true}
}

//byQolam
Posted by: Guest on October-05-2021
0

compare two arrays and make sure there are no duplicates js

array1 = array1.filter(val => !array2.includes(val));
Posted by: Guest on February-24-2021

Code answers related to "when are 2 arrays same value in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language