Skip to content

reduceArray

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));
const source$ = of([1, 2, 3]);
const reduced$ = source$.pipe(reduceArray((acc, e) => acc + e, 0));
// Output: 6
  • 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.