Loops
/ API Reference
Loops
/ API Reference

objectReduce

Reduces the object based on the provided reducer function.
Similar to Array.prototype.reduce, but for objects.

The Gist

import { objectReduce } from '@weser/loops'

const reducedObject = objectReduce(
  { a: 1, b: 2, c: 3 },
  (accumulator, value) => accumulator + value,
  0
)

// => 6
console.log(reducedObject)

Parameters

ParameterTypeDescription
objRecord<PropertyKey, any>The object to reduce.
reducer(accumulator: B, value: T[keyof T], key: keyof T, obj: T) => BThe reducer function.
initialValueBThe initial value.

Returns

(B) The reduced value.

On this page