The Array.isArray() method in vanilla JS
Today, I wanted to share a simple but useful vanilla JS method: Array.isArray()
.
You pass an item into Array.isArray()
method, and it returns true
if the item is an array or false
if it’s not. That’s it. That’s the whole method.
// returns true
Array.isArray(['Gandalf', 'Radagast']);
// returns true
Array.isArray([]);
// returns false
Array.isArray({
name: 'Radagast',
profession: 'wizard'
});
// returns false
Array.isArray(null);
// returns false
Array.isArray(42);
Situational, but handy!