0 votes
1 view
in Web Technology by (40.4k points)

I would like to check whether a variable is either an array or a single value in JavaScript.

I have found a possible solution...

if (variable.constructor == Array)...

Is this the best way this can be done?

1 Answer

0 votes
by (92.9k points)

You can check if a variable is an array in JavaScript by using the below-mentioned code:-

if (value instanceof Array) {

alert('value is Array!'); 

else { 

alert('Not an array');

}

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...