JS Built-ins
← Array25 / 226
ArrayArray.isArrayintermediate

Array.isArray() β€” check if all elements are arrays

πŸ“– Usage Example
const matrix = [[1, 2], [3, 4]]
matrix.every(Array.isArray)  // β†’ true  (all rows are arrays)

Use Array.isArray with every() to confirm all elements of an array are themselves arrays.

Array.isArray() β€” array of arrays

Using Array.isArray together with .every() lets you verify that every element of an array is itself an array β€” a useful validation when working with matrix data.

Challenge: Implement isArrayOfArrays that returns true only when the input is an array and every element is also an array.

isArrayOfArrays([[1, 2], [3, 4]]) // β†’ true
isArrayOfArrays([[1], 2, [3]])    // β†’ false
isArrayOfArrays([])               // β†’ true  (vacuously true)
πŸ’‘ Hints (2)
  • β€’ First guard with `Array.isArray(val)`, then chain `.every(Array.isArray)` on the result.
  • β€’ `.every()` short-circuits on the first failing element.