How to check a variable is an array in Javascript?

To check, you use Constructor function with a normal array:

 if(yourVariable.constructor === Array)
{
  // your code if your variable is an array
}else{
  // your code if your variable is not an array
}


For the object array:

 if(variable.prop && variable.prop.constructor === Array)
{
  // your code if your variable is an array
}else{
  // your code if your variable is not an array
}


© 2019 4codev

Created with love by Sil.