Working with arrays in JavaScript is a common activity. Sometimes we get a variable in JavaScript that we need to be an array, but we aren’t sure that it is.

Non-primitive data types in JavaScripts are all objects (functions have their own type, but they too are objects). As a result, it’s not sufficient to use the typeof operator that’s commonly used to determine a data type:

let result = { subject: 'Science', marks: 97 };
let numbers = [1, 2, 3, 4, 5];

console.log(typeof result); // Object
console.log(typeof numbers); // Object

In this article, we’ll take a look at how to check if a given variable or value is an array or not, in JavaScript.

#javascript #data structures

JavaScript: Check if Object is Array
2.05 GEEK