how to detect array in javascript code example
Example 1: js check if is array
if(Array.isArray(colors)){
//colors is an array
}
Example 2: how to recognize an array in javascript
const array = [1, 2, 3];
Array.isArray(array); // => true
Array.isArray(object); // => false
Array.isArray(string); // => false
Array.isArray(empty); // => false
// other ways
({}).toString.call(array); // => '[object Array]'
({}).toString.call(object); // => '[object Object]'
({}).toString.call(string); // => '[object String]'
({}).toString.call(empty); // => '[object Null]'