How do I know if a variable is an array?

Share:
As we already know JavaScript array is an object
JavaScript operator typeof always returns "object":

To solve this problem ECMAScript 5 defines a new method Array.isArray(),
The problem with this method is that it is not supported in older browsers.

Now we have only two trusted solutions:

Solution 1: Create your own isArray() function that will return true or false.


Solution 2: Use  instanceof operator.

Hi! I am Sartaj Husain. I am a Professional Software Developer, live in Delhi. I write blogs in my free time. I love to learn and share the knowledge with others because it is no good to try to stop knowledge from going forward. So free posts and tutorials. more..

No comments