// inside if else check
if(Array.isArray(myVarToTest)) {
// myVatToTest is an array
} else {
// myVarToTest is not an array
}
Array.isArray(yourItem)
// 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
let fruit = 'apple';
let fruits = ["apple", "banana", "mango", "orange", "grapes"];
const isArray = (arr) => Array.isArray(arr);
console.log(isArray.(fruit)); //output - false
console.log(isArray.(fruits)); //output- true
// npm i is-js-array
const { isJSArray } = require("is-js-array");
isJSArray([]); // true
isJSArray({}); // false