How to Check if a Variable is an Array in JavaScript? Last Updated : 09 Jan, 2025 Comments Improve Suggest changes Like Article Like Report To check if a variable is an array, we can use the JavaScript isArray() method. It is a very basic method to check a variable is an array or not. Checking if a variable is an array in JavaScript is essential for accurately handling data, as arrays have unique behaviors and methods. Using JavaScript isArray() MethodThe Array.isArray() method checks if a variable is an array. It returns true if the variable is an array and false otherwise. This method is introduced in ECMAScript 5.SyntaxArray.isArray( variableName ) JavaScript // Given variables let n = 10; console.log("Is Array: ", Array.isArray(n)); let s = "GeeksforGeeks"; console.log("Is Array: ", Array.isArray(s)); let a = [ 10, 20, 30, 40, 50 ]; console.log("Is Array: ", Array.isArray(a)); OutputIs Array: false Is Array: false Is Array: true Using JavaScript instanceof OperatorThe JavaScript instanceof operator is used to test whether the prototype property of a constructor appears anywhere in the prototype chain of an object. This can be used to evaluate if the given variable has a prototype of Array.Syntaxvariable instanceof Array JavaScript // Given variables let n = 10; console.log("Is Array: ", n instanceof Array); let s = "GeeksforGeeks"; console.log("Is Array: ", s instanceof Array); let a = [ 10, 20, 30, 40, 50 ]; console.log("Is Array: ", a instanceof Array); OutputIs Array: false Is Array: false Is Array: true Checking Constructor Property of VariableThe approach of checking the constructor property involves verifying if a variable's constructor is Array. If variable.constructor === Array, the variable is an array. This method checks the object's prototype chain but may fail if the array's prototype is altered.Syntaxvariable.constructor === Array JavaScript // Given variables let n = 10; console.log("Is Array: ", n.constructor === Array); let s = "GeeksforGeeks"; console.log("Is Array: ", s.constructor === Array); let a = [ 10, 20, 30, 40, 50 ]; console.log("Is Array: ", a.constructor === Array); OutputIs Array: false Is Array: false Is Array: true Comment More infoAdvertise with us Next Article How to Check if a Variable is an Array in JavaScript? sayantanm19 Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Questions +1 More Similar Reads How to check if a Variable Is Not Null in JavaScript ? In JavaScript, checking if a variable is not null ensures that the variable has been assigned a value and is not empty or uninitialized. This check is important for avoiding errors when accessing or manipulating data, ensuring that the variable holds valid, usable content before proceeding with oper 4 min read How to check if an array includes an object in JavaScript ? Check if an array includes an object in JavaScript, which refers to determining whether a specific object is present within an array. Since objects are compared by reference, various methods are used to identify if an object with matching properties exists in the array.How to check if an array inclu 3 min read How to Check if a Value is a Number in JavaScript ? To check if a value is a number in JavaScript, use the typeof operator to ensure the value's type is 'number'. Additionally, functions like Number.isFinite() and !isNaN() can verify if a value is a valid, finite number.Methods to Check if a Value is a NumberThere are various ways to check if a value 3 min read How to Check Object is an Array in JavaScript? There are two different approaches to check an object is an array or not in JavaScript.1. Using Array.isArray() MethodThe Array.isArray() method determines whether the value passed to this function is an array or not. This method returns true if the argument passed is an array else it returns false. 1 min read Check if an array is empty or not in JavaScript These are the following ways to check whether the given array is empty or not:1. The length Property - mostly usedThe length property can be used to get the length of the given array if it returns 0 then the length of the array is 0 means the given array is empty else the array have the elements.Jav 1 min read How to Check if an Element Exists in an Array in JavaScript? Given an array, the task is to check whether an element present in an array or not in JavaScript. If the element present in array, then it returns true, otherwise returns false.The indexOf() method returns the index of first occurance of element in an array, and -1 of the element not found in array. 2 min read JavaScript - Check if JS Array Includes a Value? To check if an array includes a value we can use JavaScript Array.includes() method. This method returns a boolean value, if the element exists it returns true else it returns false.1. Using Array.includes() Method - Mostly Used The JS array.includes() method returns true if the array contains the s 4 min read How to check if a value is object-like in JavaScript ? In JavaScript, objects are a collection of related data. It is also a container for name-value pairs. In JavaScript, we can check the type of value in many ways. Basically, we check if a value is object-like using typeof, instanceof, constructor, and Object.prototype.toString.call(k). All of the ope 4 min read Check if a variable is a string using JavaScript Checking if a variable is a string in JavaScript is a common task to ensure that the data type of a variable is what you expect. This is particularly important when handling user inputs or working with dynamic data, where type validation helps prevent errors and ensures reliable code execution.Below 3 min read How to Check if an Array Includes an Object in TypeScript ? In TypeScript, checking if an array includes an object consists of comparing the object's properties within the array elements. We can compare and check this using three different approaches some method, find method, and includes method. There are several ways to check if an array includes an object 3 min read Like