Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Latest commit

 

History

History
40 lines (29 loc) · 716 Bytes

object_foreach.md

File metadata and controls

40 lines (29 loc) · 716 Bytes

objects/objectForEach

Iterates over an object.

Calls the given callback function with each value and key in the object. The callback receives the value as the first argument, and key as the second.

function objectForEach(obj: object, cb: function): object

Args

obj:object
The object to iterate over.

cb:function
The callback function.

Returns

A shallow copy of the given object.

Examples

import { objectForEach } from 'utils/objects';

const values = {
    name:  'item',
    title: 'foo'
};
let actual = {};

objectForEach(values, (val, key) => {
    actual[key] = val;
});
console.log(actual);

// Outputs:
// { name: 'item', title: 'foo' }