Check whether a JS variable an array or not
Let's consider a JS array,
constauthors=['Param','Joshua'];
This is obviously an array, but if you need to check whether the data is an array or not. How do you do that check?
Using theArray.isArray
method, it is easy to find out whether the value of a variable is an array or not.
console.log(Array.isArray(authors));// true
If you pass a non-array value to the method, then it will returnfalse
.
console.log(Array.isArray(true));// falseconsole.log(Array.isArray({firstName:'Param',lastName:'Harrison'}));// false
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse