variable is Array or not?

Many times I asked this question, while taking interview, to find weather a variable is Array or not? I got different reply.
The question was intended to know, whether he knows about typeof Array. If you don’t know, please try.

So Way number 1, is to use isArray method of Array Constructor

way number 2, to use constructor property of a variable

way number 3, to use instanceof operator

I am excited to share this approach, using toString method of Object constructor, which I found going through the “requirejs” source code

Which one is better, may be the question to find? Till then, Happy Coding.

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *