Last updated 3 years ago
Was this helpful?
The Array class has a function on it called which can be used to check if something is an array.
Array
> Array.isArray('Hello, World!'); // => false > Array.isArray(['One', 2, [3]]); // => true > Array.isArray({ foo: 'bar' }); // => false > Array.isArray([]); // => true
The MDN docs provide an if it is not natively available.
if (!Array.isArray) { Array.isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; }
isArray()