/

Check if value is array in JavaScript

javascript
On this page
  • instanceof Array
  • Array.isArray
  • .constructor === Array

instanceof Array

js
[] instanceof Array // true
"test" instanceof Array // false

Array.isArray

As of ES5 there is now also:

js
Array.isArray([]) // true
Array.isArray("test") // false
Array.isArray({}) // false

.constructor === Array

js
[].constructor === Array // true
"foo".constructor === Array // false

From Stack Overflow

Edit this page
Want to make your own site like this?
Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My second brain, by Zander Martineau.