How to use Array.every() to check if all elements are equal?

const allEqual = array => array.every(value => value === array[0])

// output: false
allEqual([42, 1, 'hello'])

//output: true
allEqual([42, 42, 42])
Copy

September 27th, 2019

# Check if all elements of an array are equal

Add to bookmarks

The function checks if every element of the array is strictly equal to the first element.

HomeBookmarks