Lodash Internal `arrayEach` Utility
This package exports the internal `arrayEach` utility function from the Lodash library, specifically corresponding to `lodash` version 3.0.0, released around 2015. `arrayEach` is a foundational, optimized internal method for iterating over arrays. It differs from the public `_.forEach` in that it is strictly for arrays and doesn't handle objects or other collections. As an internal module, its primary purpose was to be consumed by other Lodash functions. While the main `lodash` library continues active development, this specific `lodash._arrayeach` module is considered a snapshot from the v3 era and has not received independent updates since its initial v3 release. Users seeking modern, maintained iteration utilities should rely on the comprehensive `lodash` package (currently v4.x) or `lodash-es` for tree-shakable builds.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'call') at Function.arrayEach
cause Attempting to call `arrayEach` with a non-array or null/undefined `collection` argument.fixEnsure the first argument passed to `arrayEach` is always an array. Example: `arrayEach([], callback);` -
TypeError: arrayEach is not a function
cause Incorrectly trying to import `arrayEach` using ES module syntax or destructuring from the CommonJS package.fixUse the correct CommonJS `require` syntax: `const arrayEach = require('lodash._arrayeach');` -
Error: Cannot find module 'lodash._arrayeach'
cause The package `lodash._arrayeach` has not been installed or is not resolvable in the current environment.fixInstall the package via npm: `npm install --save lodash._arrayeach`
Warnings
- breaking This `lodash._arrayeach` package is based on Lodash v3.0.0. The main `lodash` library moved to v4.0.0 in 2015, which introduced significant backward-incompatible changes across the entire library. Using this v3 internal module alongside a modern v4+ `lodash` installation may lead to inconsistent behavior or conflicts due to differing internal implementations.
- deprecated This package is an abandoned internal module from Lodash v3.0.0 and has not received updates since its initial release. Modern Lodash (v4.x) provides similar or improved functionality through its public API (e.g., `_.forEach` for array iteration) and `lodash-es` for modular, tree-shakable builds, which are actively maintained.
- gotcha Relying on internal modules like `lodash._arrayeach` is discouraged as they are not part of Lodash's stable public API. Their behavior, existence, and compatibility can change without warning across major versions of the main `lodash` library, leading to unexpected issues during upgrades.
- gotcha Using older versions of any library, including `lodash` and its internal modules from v3, means foregoing security patches and bug fixes. For example, `lodash` v4.18.0 fixed prototype pollution vulnerabilities in `_.unset` and `_.omit` (GHSA-f23m-r3pf-42rh) which would not be present in a v3 codebase.
Install
-
npm install lodash._arrayeach -
yarn add lodash._arrayeach -
pnpm add lodash._arrayeach
Imports
- arrayEach
import { arrayEach } from 'lodash._arrayeach';const arrayEach = require('lodash._arrayeach');
Quickstart
const arrayEach = require('lodash._arrayeach');
const numbers = [10, 20, 30, 40, 50];
const doubledNumbers = [];
console.log('Original numbers:', numbers);
arrayEach(numbers, (value, index) => {
doubledNumbers[index] = value * 2;
});
console.log('Doubled numbers:', doubledNumbers);
// Demonstrating the internal nature: it's not the public _.forEach
const sparseArray = [1, , 3]; // eslint-disable-line no-sparse-arrays
const resultSparse = [];
arrayEach(sparseArray, (value) => resultSparse.push(value === undefined ? 'undefined' : value));
console.log('ArrayEach on sparse array (handles undefined):', resultSparse);