
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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>
- Related Questions & Answers
- 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 you check if an element is present in a list in Java?
- How do I check if an array includes an object in JavaScript?
- How to check if a variable is NaN in JavaScript?
- How to check if a variable is boolean 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 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?
- How to check if a variable exists in JavaScript?
- Python - Check if a variable is string
- How do you check if a widget has a focus in Tkinter?
Advertisements