JavaScript
How to check if a variable is an array?

How to check if a variable is an array in JavaScript?

isArray

Array.isArray(variable)

instanceof vs. Array.isArray() (opens in a new tab)

When checking for Array instance, Array.isArray() is preferred over instanceof because it works across realms.

instanceof

variable instanceof Array

constructor

variable.constructor === Array

Object.prototype.toString()

Object.prototype.toString.call(variable) === '[object Array]'

References