1// inside if else check
2if(Array.isArray(myVarToTest)) {
3 // myVatToTest is an array
4} else {
5 // myVarToTest is not an array
6}
1var colors=["red","green","blue"];
2
3if(Array.isArray(colors)){
4 //colors is an array
5}
1if(Array.isArray(myVarToTest)) {
2 // myVatToTest is an array
3} else {
4 // myVarToTest is not an array
5}
1
2function isArray(value) {
3 return Object.prototype.toString.call(value) === "[object Array]";
4}