Skip to content
Go back

every() day some() time

Published:  at  10:43 AM
1 min read

Moving from Python to JavaScript, I often find myself thinking what’s the equivalent of X in JS?

Python vs JS

Two nifty-little-tricks I use regularly are Python’s built-in functions: any() and all().
Both accept an iterable and return True if any/all element/s of the iterable are true, ‘False’ otherwise.

Today I learned their JS equivalent for arrays: some() and every().
The function checks whether at least one/every element in the array passes the condition implemented by the provided callback.

Usage

[10, 11, 12, 13].every((x) => x > 10); // false
[8, 9, 10, 11].some((x) => x > 10); // true



Previous Post
CSS Variables
Next Post
Mosh Mobile Shell