JS Built-ins
← Array22 / 226
ArrayArray.isArraybeginner

Array.isArray() β€” basic check

πŸ“– Usage Example
Array.isArray([1, 2, 3])   // β†’ true
Array.isArray('hello')     // β†’ false
Array.isArray({length: 3}) // β†’ false

Use Array.isArray() to reliably check whether a value is an array.

Array.isArray()

Array.isArray(value) returns true if and only if the value is an Array object. It is the most reliable way to check for arrays β€” more reliable than instanceof Array when working across iframes or with subclasses.

Challenge: Implement isItAnArray that returns true when the value is an array and false otherwise.

isItAnArray([1, 2, 3]) // β†’ true
isItAnArray('hello')   // β†’ false
isItAnArray({})        // β†’ false
πŸ’‘ Hints (2)
  • β€’ `Array.isArray` is the canonical, spec-defined way to test for arrays.
  • β€’ It correctly returns `false` for `null`, `undefined`, objects, and strings.