Files
30-seconds-of-code/snippets/allEqual.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

586 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Check if array elements are equal array beginner 2018-08-03T00:03:08+03:00 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 NaN self-inequality.
const allEqual = arr => arr.every(val => val === arr[0]);
allEqual([1, 2, 3, 4, 5, 6]); // false
allEqual([1, 1, 1, 1]); // true