# typed-array-length

> Robustly get the length of a Typed Array

Latest version **1.0.8** (published 2026-05-28) · MIT license · 0 weekly downloads

> **Native alternative:** %TypedArray%.prototype.length — Use native JavaScript (Node 0.10.0+) (https://developer.mozilla.orgGlobal_Objects/TypedArray/length)

## Install

```sh
npm install typed-array-length
pnpm add typed-array-length
yarn add typed-array-length
bun add typed-array-length
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.8 |
| Published | 2026-05-28 |
| First published | 2020-01-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 0.4 |
| Dependencies | 6 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | typed, array, length, robust, es, Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array |

## Links

- npm: https://www.npmjs.com/package/typed-array-length
- Repository: https://github.com/inspect-js/typed-array-length
- Homepage: https://github.com/inspect-js/typed-array-length#readme
- Issues: https://github.com/inspect-js/typed-array-length/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/typed-array-length

## Dependencies (6)

- [gopd](https://npm.io/package/gopd.md) ^1.2.0
- [for-each](https://npm.io/package/for-each.md) ^0.3.5
- [call-bind](https://npm.io/package/call-bind.md) ^1.0.9
- [is-typed-array](https://npm.io/package/is-typed-array.md) ^1.1.15
- [reflect.getprototypeof](https://npm.io/package/reflect.getprototypeof.md) ^1.0.10
- [possible-typed-array-names](https://npm.io/package/possible-typed-array-names.md) ^1.1.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2026-05-28
- 1.0.7 — 2024-11-23
- 1.0.6 — 2024-03-21
- 1.0.5 — 2024-02-20
- 1.0.4 — 2022-05-24
- 1.0.3 — 2020-12-06
- 1.0.2 — 2020-04-23
- 1.0.1 — 2020-01-19
- 1.0.0 — 2020-01-19

## README

# typed-array-length <sup>[![Version Badge][2]][1]</sup>

[![dependency status][5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][11]][1]

Robustly get the length of a Typed Array, or `false` if it is not a Typed Array. Works cross-realm, in every engine, even if the `length` property is overridden.

## Example

```js
var typedArrayLength = require('typed-array-length');
var assert = require('assert');

assert.equal(false, typedArrayLength(undefined));
assert.equal(false, typedArrayLength(null));
assert.equal(false, typedArrayLength(false));
assert.equal(false, typedArrayLength(true));
assert.equal(false, typedArrayLength([]));
assert.equal(false, typedArrayLength({}));
assert.equal(false, typedArrayLength(/a/g));
assert.equal(false, typedArrayLength(new RegExp('a', 'g')));
assert.equal(false, typedArrayLength(new Date()));
assert.equal(false, typedArrayLength(42));
assert.equal(false, typedArrayLength(NaN));
assert.equal(false, typedArrayLength(Infinity));
assert.equal(false, typedArrayLength(new Number(42)));
assert.equal(false, typedArrayLength('foo'));
assert.equal(false, typedArrayLength(Object('foo')));
assert.equal(false, typedArrayLength(function () {}));
assert.equal(false, typedArrayLength(function* () {}));
assert.equal(false, typedArrayLength(x => x * x));
assert.equal(false, typedArrayLength([]));

assert.equal(1, typedArrayLength(new Int8Array(1)));
assert.equal(2, typedArrayLength(new Uint8Array(2)));
assert.equal(3, typedArrayLength(new Uint8ClampedArray(3)));
assert.equal(4, typedArrayLength(new Int16Array(4)));
assert.equal(5, typedArrayLength(new Uint16Array(5)));
assert.equal(6, typedArrayLength(new Int32Array(6)));
assert.equal(7, typedArrayLength(new Uint32Array(7)));
assert.equal(8, typedArrayLength(new Float32Array(8)));
assert.equal(9, typedArrayLength(new Float64Array(9)));
assert.equal(10, typedArrayLength(new BigInt64Array(10)));
assert.equal(11, typedArrayLength(new BigUint64Array(11)));
```

## Tests
Simply clone the repo, `npm install`, and run `npm test`

[1]: https://npmjs.org/package/typed-array-length
[2]: https://versionbadg.es/inspect-js/typed-array-length.svg
[5]: https://david-dm.org/inspect-js/typed-array-length.svg
[6]: https://david-dm.org/inspect-js/typed-array-length
[7]: https://david-dm.org/inspect-js/typed-array-length/dev-status.svg
[8]: https://david-dm.org/inspect-js/typed-array-length#info=devDependencies
[11]: https://nodei.co/npm/typed-array-length.png?downloads=true&stars=true
[license-image]: http://img.shields.io/npm/l/typed-array-length.svg
[license-url]: LICENSE
[downloads-image]: http://img.shields.io/npm/dm/typed-array-length.svg
[downloads-url]: http://npm-stat.com/charts.html?package=typed-array-length

---
_Source: https://npm.io/package/typed-array-length · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
