Ask any question about JavaScript here... and get an instant response.
Post this Question & Answer:
How can I check if a variable is an array in JavaScript? Pending Review
Asked on Mar 21, 2026
Answer
To check if a variable is an array in JavaScript, you can use the Array.isArray() method. This method returns true if the variable is an array, and false otherwise.
<!-- BEGIN COPY / PASTE -->
const myVar = [1, 2, 3];
const isArray = Array.isArray(myVar);
console.log(isArray); // Output: true
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with JavaScript best practices.- The Array.isArray() method is the most reliable way to check for arrays.
- It returns true for arrays and false for other data types.
- This method is part of the ECMAScript 5.1 standard and is widely supported in modern browsers.
Recommended Links:
