reduceArray
Import
Section titled “Import”import { reduceArray } from 'ngxtension/reduce-array';Apply a reduce function to an array emitted by an Observable.
import { of } from 'rxjs';import { reduceArray } from 'ngxtension/reduce-array';
const source$ = of([1, 2, 3]);const reduced$ = source$.pipe(reduceArray((acc, e) => acc + e, 0));Examples
Section titled “Examples”Example 1: Sum Array Elements
Section titled “Example 1: Sum Array Elements”const source$ = of([1, 2, 3]);const reduced$ = source$.pipe(reduceArray((acc, e) => acc + e, 0));// Output: 6Inputs
Section titled “Inputs”reduceFn: (accumulator: R, item: T, index: number) => R- A function to reduce each element of the array, similar to JavaScript’s.reduce()method.initialValue: R- The initial value for the accumulator.