
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How do you check if a variable is an array in JavaScript?
To check if a variable is an array, use “instanceof. The following is the syntax −
variable instanceof Array
Example
Let’s seen an example to check if the variable “sports” is an array or not?
<xmp> <html> <body> <script> var sports = [ "tennis", "football", "cricket" ]; if (sports instanceof Array) { alert('Array!'); } else { alert('Not an array'); } </script> </body> </html> </xmp>
- Related Articles
- How to check if a variable is an array in JavaScript?
- How do we check if an object is an array in Javascript?
- How to check if a variable is an integer in JavaScript?
- How do I check if an array includes an object in JavaScript?
- How Do You Make An If Statement In JavaScript That Checks If A Variable is Equal To A Certain Word?
- How to check if a variable is NaN in JavaScript?
- How to check if a variable is boolean in JavaScript?
- How do you check if an element is present in a list in Java?
- How to check if a variable exists in JavaScript?
- How do I check if a Python variable exists?
- How do you check that a number is NaN in JavaScript?
- How can I check if a JavaScript variable is function type?
- How to check whether an array is a true array in JavaScript?
- How do you check if a ResultSet is empty or not in JDBC?
- How do you check if a ResultSet is closed or not in JDBC?

Advertisements