Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

check if array has same values javascript

const allEqual = arr => arr.every(v => v === arr[0]);
allEqual([1,1,1,1]);  // true
Comment

how to check all values of an array are equal or not in javascript

// how to check all values of an array are equal or not in javascript
const allEqual = (arr) => arr.every(val => val === arr[0]);
console.log(allEqual([1, 2, 3, 4, 5, 6])); // false
console.log(allEqual([1, 1, 1, 1])); // true
Comment

js 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 :: component vs container react 
Javascript :: mongodb bulk update 
Javascript :: js random generator 
Javascript :: js get browser name and platform 
Javascript :: javascript for...of with Arrays 
Javascript :: javascript check for duplicates in array 
Javascript :: on scroll call function jquery 
Javascript :: how to use useref hook in react 
Javascript :: mongoose count 
Javascript :: local reload go to top 
Javascript :: js get each pair of values from an array of objects 
Javascript :: pass data to slot vue 
Javascript :: compare date and time in js 
Javascript :: add in to array mongoose 
Javascript :: getting data from an api 
Javascript :: javascript change right click menu 
Javascript :: Reusable Alpine.js components 
Javascript :: react form 
Javascript :: js get element by innertext 
Javascript :: vue computed 
Javascript :: javascript add element to serialized form array 
Javascript :: react router v6 lazy suspense 
Javascript :: create a simple website using javascript 
Javascript :: sequelize select fields 
Javascript :: office check in 
Javascript :: types for parameter destructuring 
Javascript :: nextelementsibling javascript 
Javascript :: next js environment variables 
Javascript :: vuejs v-model select 
Javascript :: jquery append after number of chars in string 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =