DEV Community

How to Recognize an Array

Dragoljub Bogićević on February 22, 2020

In order to distinguish whether variable is an array or not we have couple of options. But before we start it is good to mention that arrays in Ja...
Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

There are two more,

testArray.constructor === Array  // true
testArray.constructor.name === 'Array'  // true

Also, I believe .constructor.toString() === 'function Array() { [native code] }'

But if a class extends Array, most cases become false, except Array.isArray and instanceof.

Collapse
 
bogicevic7 profile image
Dragoljub Bogićević

Thank you for the response, I have included your suggestions...