JS Built-ins
← Array53 / 226
ArrayArray.prototype.everybeginner

Array.prototype.every() β€” check non-empty strings

πŸ“– Usage Example
const words = ['hello', 'world']
words.every(w => w.length > 3)   // β†’ true
words.every(w => w.startsWith('h'))  // β†’ false

Use every() to validate that all strings in an array meet a specific criterion.

Array.prototype.every() β€” string validation

every() can test any condition on any element type. Testing string length is a common use case for input validation.

Challenge: Implement allNonEmpty(strs) that returns true if every string in the array has a length greater than 0.

allNonEmpty(['hello', 'world']) // β†’ true
allNonEmpty(['hello', ''])     // β†’ false
πŸ’‘ Hints (2)
  • β€’ `s.length > 0` is truthy for any non-empty string.
  • β€’ You can also write `s => !!s` or `Boolean` as the callback.