# array.prototype.foreach

> An ES spec-compliant `Array.prototype.forEach` shim/polyfill/replacement that works as far down as ES3.

Latest version **1.0.7** (published 2024-03-19) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install array.prototype.foreach
pnpm add array.prototype.foreach
yarn add array.prototype.foreach
bun add array.prototype.foreach
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2024-03-19 |
| First published | 2021-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >= 0.4 |
| Dependencies | 7 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jordan Harband |
| Maintainers | ljharb |
| Keywords | Array.prototype.forEach, forEach, array, ecmascript, ES, shim, polyfill, es-shim API |

## Links

- npm: https://www.npmjs.com/package/array.prototype.foreach
- Repository: https://github.com/es-shims/Array.prototype.forEach
- Homepage: https://github.com/es-shims/Array.prototype.forEach#readme
- Issues: https://github.com/es-shims/Array.prototype.forEach/issues
- Funding: https://github.com/sponsors/ljharb
- npm.io page: https://npm.io/package/array.prototype.foreach

## Dependencies (7)

- [call-bind](https://npm.io/package/call-bind.md) ^1.0.7
- [es-errors](https://npm.io/package/es-errors.md) ^1.3.0
- [is-string](https://npm.io/package/is-string.md) ^1.0.7
- [es-abstract](https://npm.io/package/es-abstract.md) ^1.23.2
- [es-object-atoms](https://npm.io/package/es-object-atoms.md) ^1.0.0
- [define-properties](https://npm.io/package/define-properties.md) ^1.2.1
- [es-array-method-boxes-properly](https://npm.io/package/es-array-method-boxes-properly.md) ^1.0.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.7 (latest) — 2024-03-19
- 1.0.6 — 2024-02-05
- 1.0.5 — 2023-09-05
- 1.0.4 — 2022-11-03
- 1.0.3 — 2022-11-03
- 1.0.2 — 2021-10-01
- 1.0.1 — 2021-08-17
- 1.0.0 — 2021-08-07

## README

# array.prototype.foreach <sup>[![Version Badge][npm-version-svg]][package-url]</sup>

[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][deps-svg]][deps-url]
[![dev dependency status][dev-deps-svg]][dev-deps-url]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]

[![npm badge][npm-badge-png]][package-url]

An ES spec-compliant `Array.prototype.forEach` shim/polyfill/replacement that works as far down as ES3.

This package implements the [es-shim API](https://github.com/es-shims/api) interface. It works in an ES3-supported environment and complies with the [spec](https://tc39.es/ecma262/#sec-array.prototype.foreach).

Because `Array.prototype.forEach` depends on a receiver (the `this` value), the main export takes the array to operate on as the first argument.

## Getting started

```sh
npm install --save array.prototype.foreach
```

## Usage/Examples

```js
var forEach = require('array.prototype.foreach');
var assert = require('assert');

var arr = [1, [2], [], 3, [[4]]];
var counter = 0;
var increaseCounter = function (x) { counter += 1; };

assert.equal(forEach(arr, increaseCounter), undefined);
assert.equal(counter, arr.length);
```

```js
var forEach = require('array.prototype.foreach');
var assert = require('assert');
/* when Array#forEach is not present */
delete Array.prototype.forEach;
var shimmed = forEach.shim();
var counter = 0;

assert.equal(shimmed, forEach.getPolyfill());
assert.equal(arr.forEach(increaseCounter), forEach(arr, increaseCounter));
assert.equal(counter, arr.length * 2);
```

```js
var forEach = require('array.prototype.foreach');
var assert = require('assert');
/* when Array#forEach is present */
var shimmed = forEach.shim();
var counter = 0;

assert.equal(shimmed, Array.prototype.forEach);
assert.equal(arr.forEach(increaseCounter), forEach(arr, increaseCounter));
assert.equal(counter, arr.length * 2);
```

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

[package-url]: https://npmjs.org/package/array.prototype.foreach
[npm-version-svg]: https://versionbadg.es/es-shims/Array.prototype.forEach.svg
[deps-svg]: https://david-dm.org/es-shims/Array.prototype.forEach.svg
[deps-url]: https://david-dm.org/es-shims/Array.prototype.forEach
[dev-deps-svg]: https://david-dm.org/es-shims/Array.prototype.forEach/dev-status.svg
[dev-deps-url]: https://david-dm.org/es-shims/Array.prototype.forEach#info=devDependencies
[npm-badge-png]: https://nodei.co/npm/array.prototype.foreach.png?downloads=true&stars=true
[license-image]: https://img.shields.io/npm/l/array.prototype.foreach.svg
[license-url]: LICENSE
[downloads-image]: https://img.shields.io/npm/dm/array.prototype.foreach.svg
[downloads-url]: https://npm-stat.com/charts.html?package=array.prototype.foreach
[codecov-image]: https://codecov.io/gh/es-shims/Array.prototype.forEach/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/es-shims/Array.prototype.forEach/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/es-shims/Array.prototype.forEach
[actions-url]: https://github.com/es-shims/Array.prototype.forEach

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