586 B
586 B
title, type, language, tags, cover, dateModified
| title | type | language | tags | cover | dateModified | |
|---|---|---|---|---|---|---|
| Check if array elements are equal | snippet | javascript |
|
shelf-plant | 2020-10-18T20:24:28+03:00 |
Checks if all elements in an array are equal.
- Use
Array.prototype.every()to check if all the elements of the array are the same as the first one. - Elements in the array are compared using the strict comparison operator, which does not account for
NaNself-inequality.
const allEqual = arr => arr.every(val => val === arr[0]);
allEqual([1, 2, 3, 4, 5, 6]); // false
allEqual([1, 1, 1, 1]); // true