Comparison of the top Array verification utilities on npm
Tags: javascript
Published: 2018-04-13 16:21:00

---
title: Comparison of the top Array verification utilities on npm
published: true
tags: javascript
canonical_url: https://blog.logrocket.com/comparison-of-the-top-array-verification-utilities-on-npm-128dda083b8c
---

![](https://cdn-images-1.medium.com/max/1024/1*lla6x9C9gvtRXkykD3OJ6w.png)<figcaption>Source: <a href="http://www.monkeyuser.com/2017/npm-delivery/">http://www.monkeyuser.com/2017/npm-delivery/</a></figcaption>

A few weeks ago, I was working on my side project, array-length, a highly performant new JavaScript library for calculating the number of elements in a JavaScript array, when I faced an interesting challenge. I needed a way of validating that a users’ input was truly an array, and not some other type of object that might break my algorithm’s complex control flow.

As is often the case with any sufficiently lucrative business opportunity, there are a variety of solutions on the market that aim to solve this problem. They range from focused, best-of-breed libraries ideal for startups and mid-market customers, to highly scalable, enterprise-grade solutions that offer a wide range of functionality.

Given the myriad of options, I was surprised to find that little literature exists to help a buyer make an informed decision. Perhaps the array verification market is too new to be covered by the likes of Gartner and Forrester, my typical sources for reviews on JavaScript libraries.

Instead, I decided to spend a few weeks surveying the landscape and writing up my findings. Below you’ll find my summary of the top three solutions across a variety of metrics including performance, scalability, maintainability, interoperability, debuggability, readability, and web-scaleability.

[![LogRocket Free Trial Banner](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2017/03/f760c-1gpjapknnuyhu8esa3z0jga.png?resize=1200%2C280&ssl=1)](https://logrocket.com/signup/)

### isarray

isarray is an excellent npm package that can accurately detect whether its given argument is or is not an array. While the README states that, “_isarray is for older browsers and deprecated Node.js versions.”_ I found that it works quite well with new browsers and the latest version of Node.

It take a single argument and returns a boolean of whether or not the given object is indeed an Array.

#### Usage

```jsx
var isArray = require('isarray');
console.log(isArray([])); // => true
console.log(isArray({})); // => false
```

**Pros**

- concise, highly-expressive syntax
- works well with MongoDB
- Excellent ROI (only 2 month pay back period)

**Cons**

- No 3rd party plugin ecosystem
- 3 open GitHub issues

### is-array

is-array takes a wildly different approach to JavaScript array verification, opting for a hyphen instead of an empty string between is and array in the package title. It offers significantly improved readability over the compound title of isarray while still providing the majority of the functionality expected by the discerning engineer.

It take a single argument and returns a boolean of whether or not the given object is indeed an Array.

#### Usage

```jsx
var isArray = require('is-array');
console.log(isArray([])); // => true
console.log(isArray({})); // => false
```

**Pros**

- It’s cool because it’s less popular

**Cons**

- longer name means larger source code (slower Git pushes, less free hard drive space, etc)
- Permissive MIT license means a large company could Embrace, Extend and Extinguish it

### Array.isArray()

A last resort, suitable only in cases when 3rd party modules are not allowed (enterprise security constraints, use on a dessert island, etc), Array.isArray() is a built-in JavaScript method that was introduced along with the ES5 standard.

It take a single argument and returns a boolean of whether or not the given object is indeed an Array.

#### Usage

```jsx
console.log(Array.isArray([])); // => true
console.log(Array.isArray({})); // => false
```

**Pros**

- At least 95% accurate

**Cons**

- Not on npm
- Not supported in Opera 4
- Will throw an error if you try to import it with webpack

### References

- [https://www.npmjs.com/package/isarray](https://www.npmjs.com/package/isarray)
- [https://www.npmjs.com/package/is-array](https://www.npmjs.com/package/is-array)
- [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global\_Objects/Array/isArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray)

_Rog Locket is a developer and humorist who writes a weekly satirical column for the LogRocket blog. He is entirely fictional._
* * *
### Plug: LogRocket, a DVR for web apps

[![](https://cdn-images-1.medium.com/max/1024/1*s_rMyo6NbrAsP-XtvBaXFg.png)](http://logrocket.com)

[LogRocket](https://logrocket.com) is a frontend logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store.

In addition to logging Redux actions and state, LogRocket records console logs, JavaScript errors, stacktraces, network requests/responses with headers + bodies, browser metadata, and custom logs. It also instruments the DOM to record the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single page apps.

Try it for free.
* * *