Check if a JavaScript Variable is an Array with isArray() [Examples] Skip to content Menu Menu Linux Shell Applications Raspberry Pi Tips Unix Distros Ubuntu Centos Debian Fedora Programming Javascript Perl PHP Python Databases Networking Cron Jobs Cron Jobs Every x Minutes Cron Jobs Every x Hours Cron Jobs Every x Days Cron Jobs on Certain Weekdays Cron Jobs Every x Months Miscellaneous Cron Jobs Home » Programming » Javascript » Check if a JavaScript Variable is an Array with isArray() [Examples] Check if a JavaScript Variable is an Array with isArray() [Examples] October 15, 2021 by Brad Morton Here’s a short article that explains arrays and how to check if a JavaScript variable is an array using the Array.isArray() method. Want to check out whether an array contains a value? Find out how here. What is An Array? An array is a type of JavaScript variable that can hold other variables, or references to other variables, in a list at a certain position. Declaring an Array in JavaScript An array is declared in JavaScript the same way as any other variable – by assigning the value to a variable name. An array is constructed using square brackets ([]) to contain the array values, which are separated by a comma (,) – here it is in code: var myArray = ['dog', 'cat', 'pig']; Above, an array variable called myArray is declared with the value of an array containing the strings dog cat and pig. Each element in the array is its own value, contained within the array at a certain position (index). Checking for Arrays using Array.isArray() If you have a variable that could take on any number of values (for example, from reading a file or user input) and you want to check whether or not it is an array – the Array.isArray() method is the tool that does just that. Here’s how it’s used: var myArray = ['dog', 'cat', 'pig'];