- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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>
Advertisements