![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
foreach-prop
Advanced tools
Array-like methods for objects
npm install foreach-prop
similar to Array.prototype.forEach
. It executes the provided callback function for every key-value-pair in the object. Once iniciated there is no way to stop the execution of this function, if you intend to stop the iteration at some point have a look at findKey
method.
forEach(object, function callback(value, key, ...extra) => void, ...extra): void;
The callback function inherits the this
value from the function call, so if you want a specific this
value in your callback function, you can call it using the call
method of the Function.prototype
...
forEach.call(thisArg, object, callback, ...extra);
similar to Array.prototype.map
. It executes the provided callback function for every key-value-pair in the object and returns a new object.
map(object, function callback(value, key, ...extra) => any, ...extra): object;
The callback function inherits the this
value from the function call, so if you want a specific this
value in your callback function, you can call it using the call
method of the Function.prototype
...
map.call(thisArg, object, callback, ...extra);
similar to Array.prototype.indexOf
. It returns the key of the first value that equals the provided one.
keyOf(object, value): string;
similar to Array.prototype.lastIndexOf
. It returns the key of the last value that equals the provided one.
lastKeyOf(object, value): string;
similar to Array.prototype.findIndex
. It executes the provided callback function for every key-value-pair in the object and returns the key once the provided callback function return a truthy value. It returns null
if nothing found.
findKey(object, function callback(value, key, ...extra) => any, ...extra): string;
The callback function inherits the this
value from the function call, so if you want a specific this
value in your callback function, you can call it using the call
method of the Function.prototype
...
findKey.call(thisArg, object, callback, ...extra);
similar to Array.prototype.find
. It executes the provided callback function for every key-value-pair in the object and returns the value once the provided callback function return a truthy value. It returns undefined
if nothing found.
find(object, function callback(value, key, ...extra) => any, ...extra): any;
Note that the returned value may be undefined
even if the condition is met and the value is undefined
.
const something; // something is undefined
const value = find({ something }, (val, key) => (key === "something"));
console.log(value); // it logs undefined because something is undefined
The callback function inherits the this
value from the function call, so if you want a specific this
value in your callback function, you can call it using the call
method of the Function.prototype
...
find.call(thisArg, object, callback, ...extra);
similar to Array.prototype.filter
. It executes the provided callback function for every key-value-pair in the object and returns a new object containing the key-value-pairs corresponding to those where the provided callback function returned a truthy value.
filter(object, function callback(value, key, ...extra) => any, ...extra): object;
The callback function inherits the this
value from the function call, so if you want a specific this
value in your callback function, you can call it using the call
method of the Function.prototype
...
filter.call(thisArg, object, callback, ...extra);
similar to Array.prototype.reduce
but with a major difference: if no initial value provided it defaults to undefined
.
reduce(object, function callback(current, value, key, ...extra) => any, initial, ...extra): any;
The callback function inherits the this
value from the function call, so if you want a specific this
value in your callback function, you can call it using the call
method of the Function.prototype
...
reduce.call(thisArg, object, callback, initial, ...extra);
0.2.0 (2019-MAY-04)
some
, every
& includes
methodsFAQs
Array-like methods for objects
We found that foreach-prop demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.