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

check if array has same values javascript

const allEqual = arr => arr.every(v => v === arr[0]);
allEqual([1,1,1,1]);  // 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

js check if all array values are the same

const allEqual = arr => arr.every( v => v === arr[0] )
allEqual( [1,1,1,1] )  // true
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 :: how remove the spaces from the string, then return the resultant string 
Javascript :: node.js util module 
Javascript :: formdata array of objects 
Javascript :: add array to array javascript 
Javascript :: nextjs global scss variables 
Javascript :: js html tag valu 
Javascript :: js execute string 
Javascript :: nodejs redis setex 
Javascript :: fabric download 
Javascript :: js undici fetch data 
Javascript :: jquery convert time to 1day 2 minutes 4 seconds 
Javascript :: set node_env in windows 
Javascript :: get the state of a checkbox 
Javascript :: angular is not defined In AngularJS 
Javascript :: run onclick function once javascript 
Javascript :: copy text to clipboard reactjs 
Javascript :: bootstap jquery 
Javascript :: ajax select2 
Javascript :: regex find first instace 
Javascript :: css class list 
Javascript :: parse time in javascript 
Javascript :: javascript html append 
Javascript :: how to get key from value in javascript 
Javascript :: sfc in react 
Javascript :: jszip angular 
Javascript :: addition of all elements of array in js 
Javascript :: sqrt javascript 
Javascript :: how to check password and confirm passwor in joi 
Javascript :: debug react routes 
Javascript :: how to read a csv file in nodejs 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =