ndarray
📈 Multidimensional arrays for JavaScript
ndarray adds multidimensional arrays to JavaScript
A modular library that creates higher dimensional views over typed arrays for Node and the browser.
What ndarray provides
ndarray is a modular library that brings multidimensional arrays to JavaScript. The readme explains that ndarrays provide higher dimensional views of one dimensional arrays, and shows how a length four typed array can be turned into a two by two matrix view. Once an nd array exists, elements are accessed with the set and get methods, and the readme demonstrates this with an implementation of Conway's Game of Life that reads neighbor states through get and writes the next state through set. One notable property is that views can be pulled out without copying the underlying elements: the readme shows creating a five by five array, taking a sub view with hi and lo, writing into that view, and seeing the changes reflected in the original because both share the same storage. ndarrays can be transposed, flipped, sheared, and sliced in constant time per operation. The readme lists the things they are useful for representing: images, audio, volume graphics, matrices, strings, and more. They work in Node.js and with browserify, so the same code can run server side or in a bundled browser build. The project reports 1243 stars and 58 forks on GitHub. For developers coming from MATLAB or numpy, the repository links to a dedicated guide that maps those mental models onto ndarray.
Install and API shape
Installing ndarray is done with npm install ndarray, and the library can also be used in a browser with any tool that follows CommonJS or Node module conventions, with browserify named as the most direct route and beefy suggested for live reloading. Once installed, the default export is the constructor, called as ndarray(data, shape, stride, offset). The data argument is the underlying one dimensional storage and may be a standard Array, a typed array, or any object that implements get, set, and length. Shape is the view shape and defaults to the data length. Stride is the layout of the array and defaults to row major. Offset is where the view starts and defaults to zero. The constructor returns an n dimensional view over the buffer. The central idea is the view: it keeps a separate stride so the same data structure can represent both row major and column major storage. The view object exposes four members: array.data for the underlying storage, array.shape for the dimensions, array.stride for the memory layout, and array.offset for the starting point. Element access through get(i, j, ...) is implemented as an affine projection into the one dimensional storage using the offset and strides. This design is what lets slicing and transposing stay cheap.
Ecosystem and use
The readme points to a large ecosystem of ndarray compatible modules documented in the sci js documentation, and notes a big list of such modules exists for tasks built on top of the core view abstraction. Because ndarray is modular and dependency light, it serves as a foundation that other scientific and creative coding packages build on, rather than a monolithic numeric library. The constant time slicing and the ability to wrap existing typed arrays without copying make it a good fit for image processing, signal work, and small simulation code where allocating copies would be wasteful. The Game of Life example in the readme is a compact illustration of how neighbor lookups stay readable while the underlying buffer is a flat typed array. The project's age and star count suggest it has been a stable building block in the sci js community for some time. The MIT license lets it be embedded in proprietary or open products without friction. For a JavaScript developer who needs tensor like indexing without pulling in a large linear algebra stack, ndarray offers a small, focused primitive that interoperates with the rest of the typed array world and with the broad set of modules that already speak the ndarray interface. The repository includes build and stability badges from its earlier tooling.
Editorial conclusion
The repository is published under the MIT license and its most recent commit was on 2026-08-26.
Community notes