Skip to content

Latest commit

 

History

History
58 lines (47 loc) · 2.27 KB

forOwnReduce.md

File metadata and controls

58 lines (47 loc) · 2.27 KB

Object Agent

A javascript library for working with objects

npm build coverage deps size vulnerabilities license


forOwnReduce(object, callback, initialValue) ⇒ unknown

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

Returns: unknown - The accumulated result.

Param Type Description
object object The object to iterate over.
callback function Provides three args: result, value, and key. If the result is only mutated then you may not need to return it.
initialValue unknown The initial value passed into the callback as result.

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']]