Bisexual Pride

In JavaScript, it’s easy to check if a value is an array. You can use the static Array.isArray() method, introduced in ES5:

// True because `fruits` is an array
const fruits = ['Guava', 'Mango', 'Papaya'];
Array.isArray(fruits); // true

// False because `vegetable` is a string
const vegetable = 'Leek';
Array.isArray(vegetable); // false

If you need earlier browser support than IE9—though I can’t imagine why—there’s a polyfill you can include. Under the hood, it uses the same technique my friend Chris Ferdinandi mentions here: True type checking with vanilla JS.

Learn more about Array.isArray() in the MDN Web Docs.