Array.isArray(yourItem)
Array.isArray(something);
// how to check value is array or not in javascript
const str = "foo";
const check = Array.isArray(str);
console.log(check);
// Result: false
const arr = [1,2,3,4];
const output = Array.isArray(arr);
console.log(output);
// Result: true
function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
}
Method 1: Using the isArray method
Array.isArray(variableName)'
Method 2:
variable instanceof Array
Method 3:
variable.constructor === Array
// npm i is-js-array
const { isJSArray } = require("is-js-array");
isJSArray([]); // true
isJSArray({}); // false