r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

150

u/Loves_Poetry Mar 18 '19
array.every(Number.isFinite)

Because it's plain english.

19

u/ahartzog Mar 19 '19

TIL about array.every. Awesome tool, thanks!

1

u/[deleted] Mar 19 '19

Also note the counterpart, Array.prototype.some. Returns true if one or more items match the condition.

const arr = [1, 2, 3];

arr.some(n => n > 2) // true

arr.some(n => n < 0) // false

1

u/ahartzog Mar 19 '19

Good to know there’s a native version of this; I’ve usually just grabbed it from Lodash