Skip to content

Check if all elements in an array are equal using JavaScript

const allEqual = arr => arr.every(val => val === arr[0]);

allEqual ([1, 2, 3, 4, 5, 6]); // false
allEqual ([1, 1, 1, 1]); // true
See also  Python code snippet - How to remove first row of numpy array?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.