Static Array Methods
Learn the static methods that live on the Array constructor itself — Array.isArray(), Array.from(), and Array.of() — for checking, creating, and converting arrays.
Reading Time
15 min
Lesson
Lesson 21 of 48
Introduction
Every method you've seen so far — push(), map(), sort(), and the rest — is an instance method, meaning you call it on an actual array you already have. Static methods are different: they live directly on the Array constructor and don't require an existing array to call them on. Instead, they're typically used to check whether something is an array, or to build a new array from scratch out of some other kind of data. The three you'll use most often are Array.isArray(), Array.from(), and Array.of().
Methods Overview
| Method | Purpose | Returns |
|---|---|---|
| Array.isArray() | Check whether a value is an array | A boolean |
| Array.from() | Build an array from an iterable or array-like object | A new array |
| Array.of() | Build an array from a list of arguments | A new array |
Array.isArray()
Array.isArray() checks whether the value passed to it is an array, returning true or false. This is more reliable than using typeof, because typeof returns "object" for arrays, objects, and null alike — it can't tell them apart. Array.isArray() is especially useful when a function might receive either a single item or an array of items, and you need to branch your logic depending on which one it got.
Array.isArray() Example
Console Output
Click “Run” to see the console output here.
Array.from()
Array.from() creates a new array from an iterable (like a string, Set, or Map) or an array-like object (something with a length property and indexed elements, like arguments or a NodeList). It also accepts an optional second argument — a map function — that gets applied to every element as the array is built, similar to chaining .map() immediately afterward but in a single step. This makes Array.from() a common tool for converting things that look like arrays, but aren't quite arrays, into real ones you can use array methods on.
Array.from() Example
Console Output
Click “Run” to see the console output here.
Array.of()
Array.of() creates a new array from whatever arguments you pass to it, treating each argument as an element of the resulting array. This sounds like exactly what the Array() constructor already does, and usually it is — except for one well-known edge case: calling Array(7) creates an empty array with a length of 7, while Array.of(7) creates an array containing the single element 7. Array.of() exists specifically to avoid that inconsistency.
Array.of() Example
Console Output
Click “Run” to see the console output here.
Static vs. Instance Methods
Remember the distinction: static methods like Array.isArray(), Array.from(), and Array.of() are called on the Array constructor itself, not on an array instance — you'll never write myArray.isArray(). Instance methods like map(), filter(), and sort() are called on an actual array value. If you find yourself trying to call Array.from() on a variable holding an array, you likely want to use the array directly instead.
Important
Array.from() only applies its map function while building the array — you can't retroactively add one after the array already exists without a separate .map() call. Also remember that Array-like objects need a length property; passing something without one, such as a plain object with arbitrary keys, will produce an empty array rather than an error, which can be a silent source of bugs.