Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

Array#reduce() and Array#reduceRight() typically produce hard-to-read and less performant code. In almost every case, they can be replaced by .map(), .filter(), or a for…of loop, which are easier to follow and debug.
Recommendedrecommended
Fixable
Suggestions

Examples

array.reduce(reducer);
array.reduce(reducer, initialValue);
array.reduceRight(reducer, initialValue);

// Also caught via indirect calls
[].reduce.call(array, reducer);
[].reduce.apply(array, [reducer, initialValue]);
Array.prototype.reduce.call(array, reducer);

Configuration

eslint.config.js
export default [
  {
    rules: {
      'unicorn/no-array-reduce': ['error', { allowSimpleOperations: true }],
    },
  },
];

allowSimpleOperations

Type: boolean — Default: true When true (the default), reduce calls whose callback body is a single binary expression are allowed. This covers the common case of summing numbers or concatenating strings.
// Allowed when allowSimpleOperations: true
array.reduce((total, item) => total + item);
array.reduce((total, item) => { return total + item; });
Set to false to ban reduce entirely:
// Reported even with a simple binary expression
array.reduce((total, item) => total + item); // ❌
If you rely on functional programming patterns and need reduce, you can disable the rule entirely or use an eslint-disable-next-line unicorn/no-array-reduce comment on individual call sites.

Build docs developers (and LLMs) love