check for array in javascript code example
Example 1: if object is array javascript
Array.isArray(object);
Example 2: javascript test if it is an array
if (Array.isArray(object)) {
} else {
}
Array.isArray([1, 2, 3, 4]);
Array.isArray(4);
Example 3: javascript typeof array
Array.isArray(arr)
Example 4: js check if array
Array.isArray([1, 2, 3]);
Array.isArray('asdf');
Example 5: how to check if something is array javascript
function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
}
Example 6: javascript check if in array
var extensions = ["image/jpeg","image/png","image/gif"];
if(extensions.indexOf("myfiletype") === -1){
alert("Image must be .png, .jpg or .gif");
}