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// Check if something is an Array
2// just like you do with "typeof"
3Array.isArray([1, 2, 3]); // true
4Array.isArray('asdf'); // false