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

PREVIOUS NEXT
Code Example
Javascript :: getelementbytagname javascript 
Javascript :: stripe npm 
Javascript :: sequelize custom primary key 
Javascript :: javascript work out age from date of birth 
Javascript :: javascript get element by class name change style 
Javascript :: smallest common multiple javascript 
Javascript :: how to replace non alpha numeric characters in javascript 
Javascript :: why my bootstrap classes is not working on onclick event in react 
Javascript :: get current url last part angular 
Javascript :: ng generate component in folder 
Javascript :: max_safe_integer 
Javascript :: query selector click event 
Javascript :: firebase realtime database delete child 
Javascript :: moving a item fro index to another index, javascript 
Javascript :: flutter jsonDecode UTF8 
Javascript :: react native flatlist pull to refresh 
Javascript :: javascript log error without traceback 
Javascript :: if odd js 
Javascript :: js parse cookie string 
Javascript :: slick on init 
Javascript :: jquery datatables turn off sorting 
Javascript :: email validation regex 
Javascript :: split words in javascript 
Javascript :: Count Backwards With a For Loop 
Javascript :: jquery change value 
Javascript :: An accessor cannot be declared in an ambient context. 
Javascript :: prettier semicolon false in javascript 
Javascript :: js go back 
Javascript :: regular expression javascript for phone number 
Javascript :: mongoose.connect localhost 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =