Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

Easy Way to Check if 2 Arrays are Equal in JavaScript

const d = [1,2,4,5,6];
const c = [1,2,4,5,6];

if (JSON.stringify(d) === JSON.stringify(c)) console.log('Equal!');
Comment

javascript check if two arrays contain same values

const a = ['Left', 'Right'];
const b = ['Right', 'Left'];

//	true if a and b contain the same values
//	false otherwise
const c = a.sort().join(',') === b.sort().join(',');
Comment

check if two array contains the same values js, array

const areEqual = (arr1, arr2) =>
  arr1.sort().join(',') === arr2.sort().join(',');
const arr1 = [1, 2, 3, 4];
const arr2 = [3, 4, 1, 2];
const arr3 = [1, 2, 3];
console.log(areEqual(arr1, arr2)); // true
console.log(areEqual(arr1, arr3)); // false
Comment

how to check two different length array values are equal in javascript

var a = [2, 4, 10];
var b = [1, 4];

var newArray = [];

for (var i = 0; i < a.length; i++) {
    // we want to know if a[i] is found in b
    var match = false; // we haven't found it yet
    for (var j = 0; j < b.length; j++) {
        if (a[i] == b[j]) {
            // we have found a[i] in b, so we can stop searching
            match = true;
            break;
        }
        // if we never find a[i] in b, the for loop will simply end,
        // and match will remain false
    }
    // add a[i] to newArray only if we didn't find a match.
    if (!match) {
        newArray.push(a[i]);
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: difference between let and var in javascript 
Javascript :: convert image object to blob javascript 
Javascript :: javascript getting input from console 
Javascript :: clear value input jquery 
Javascript :: react native npm run start port 
Javascript :: best and fastest encrypt and decrypt value in javascript 
Javascript :: javascript array size 
Javascript :: header logo react native img 
Javascript :: remove classname to node 
Javascript :: fonction fleche javascript 
Javascript :: jquery .click function call 
Javascript :: updateone mongoose example 
Javascript :: onchange input jquery 
Javascript :: find a single element in array of objects javascript 
Javascript :: react-router-dom useLocation 
Javascript :: how to make input field empty in javascript 
Javascript :: array map destructuring 
Javascript :: react import json 
Javascript :: js set iframe src 
Javascript :: javascript object.assign 
Javascript :: how to get thumbnail image from video file in javascript 
Javascript :: js hide div 
Javascript :: ipify api 
Javascript :: how can ic get the id of div jq 
Javascript :: group all items with same name js 
Javascript :: javascript last child 
Javascript :: javascript generate random number 
Javascript :: javascript highlight words 
Javascript :: click a link with javascript 
Javascript :: toarray javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =