Array Every and Some in JavaScript

Level 3142 keystrokes

every() checks if all elements pass a test, some() checks if at least one does.

JavaScript code

// Create an array of even numbers
1const nums = [2, 4, 6, 8];
// every() returns true if ALL elements satisfy the condition
// All numbers are even, so returns true
2console.log(nums.every(n => n % 2 === 0));
// some() returns true if AT LEAST ONE element satisfies the condition
// 6 and 8 are > 5, so returns true
3console.log(nums.some(n => n > 5));
// No number is > 10, so returns false
4console.log(nums.some(n => n > 10));

Output

true
true
false
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this JavaScript code and how often they appear.

  • =× 7
  • .× 6
  • (× 6
  • )× 6
  • >× 5
  • ;× 4
  • ,× 3
  • [× 1
  • ]× 1
  • %× 1

More JavaScript examples at level 3

← JavaScript typing practice