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 Apr 18, 2026
Answer
To check if a variable is an array in JavaScript, you can use the Array.isArray() method, which is the most reliable and straightforward approach.
<!-- BEGIN COPY / PASTE -->
const myVariable = [1, 2, 3];
const isArray = Array.isArray(myVariable);
console.log(isArray); // true
<!-- END COPY / PASTE -->Additional Comment:
✅ Answered with JavaScript best practices.- The Array.isArray() method returns true if the variable is an array, otherwise false.
- This method is preferred over other techniques like instanceof because it correctly identifies arrays across different frames or windows.
- Always use Array.isArray() for checking arrays to ensure compatibility and reliability.
Recommended Links:
