@monstermann/fn
Version:
A utility library for TypeScript.
26 lines (24 loc) • 609 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/object/forEach.ts
/**
* `forEach(target, fn)`
*
* Executes `fn` function for each key-value pair in `target` object and returns the original object.
*
* ```ts
* forEach({ a: 1, b: 2 }, ([key, value]) => console.log(key, value)); // { a: 1, b: 2 }
* ```
*
* ```ts
* pipe(
* { a: 1, b: 2 },
* forEach(([key, value]) => console.log(key, value)),
* ); // { a: 1, b: 2 }
* ```
*/
const forEach = dfdlT((target, fn) => {
for (const key of Object.keys(target)) fn([key, target[key]], target);
return target;
}, 2);
//#endregion
export { forEach };