Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Latest commit

 

History

History
58 lines (47 loc) · 2.18 KB

forOwnReduce.md

File metadata and controls

58 lines (47 loc) · 2.18 KB

Object Agent

A javascript library for working with objects

npm build coverage deps size vulnerabilities license


forOwnReduce(object, callback, initialValue) ⇒ *

Iterates over own properties of an object and returns a reduced value

Returns: * - The accumulated result

Param Type Description
object Object
callback function Provides three args: result, value, and key. If the result is only mutated then you may not need to return it.
initialValue *

Example

import { forOwnReduce } from 'object-agent';

const thing = {
    a: 'b',
    c: 'd'
};

const output = forOwnReduce(thing, (result, value, key) => {
    result.push([value, key]);
    return result;
}, []);

console.log(output);
// => [['b', 'a'], ['d', 'c']]