Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

array.prototype.foreach

es-shims370.6kMIT1.0.7

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

Array.prototype.forEach, forEach, array, ecmascript, ES, shim, polyfill, es-shim API

readme

array.prototype.foreach Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

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

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the spec.

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

npm install --save array.prototype.foreach

Usage/Examples

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);
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);
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

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

v1.0.7 - 2024-03-19

Commits

  • [meta] remove useless ESM ef23d46
  • [Deps] update call-bind, es-abstract, es-errors c855e3b
  • [actions] remove redundant finisher 83f3c19
  • [Refactor] use es-object-atoms instead of es-abstract 01a05ac
  • [Dev Deps] update aud 34a0bc8

v1.0.6 - 2024-02-04

Commits

  • [Deps] update call-bind, define-properties, es-abstract, get-intrinsic 2513ece
  • [Refactor] use es-errors where possible, so things that only need those do not need get-intrinsic 0b0d47e
  • [Dev Deps] update aud, tape 221fd86

v1.0.5 - 2023-09-05

Commits

  • [Deps] update define-properties, es-abstract, get-intrinsic bf79499
  • [Dev Deps] update @es-shims/api, @ljharb/eslint-config, aud, tape e7c2dfe

v1.0.4 - 2022-11-03

Commits

  • [Deps] update define-properties, es-abstract, get-intrinsic c8a2b71
  • [Dev Deps] update eslint, @ljharb/eslint-config, aud, auto-changelog, functions-have-names, tape d59590f
  • [eslint] remove .eslintignore 59e7346

v1.0.3 - 2022-11-02

Commits

  • [actions] reuse common workflows e638cf0
  • [Dev Deps] update eslint, @ljharb/eslint-config, @es-shims/api, safe-publish-latest, tape 7f9b6e8
  • [actions] update rebase action to use reusable workflow 7c882be
  • [actions] update codecov uploader df4cca2
  • [Deps] update es-abstract 90e7402

v1.0.2 - 2021-10-01

Commits

  • [Deps] update es-abstract ad43be9
  • [readme] fix URLs 88f6654
  • [Dev Deps] update @ljharb/eslint-config, @es-shims/api a3e7bdd

v1.0.1 - 2021-08-16

Commits

  • [Fix] remove mjs entry points 8ade8d9
  • [meta] fix "ESNext" to "ES" 0d461e5

v1.0.0 - 2021-08-07

Commits