---
# Don't modify this file manually. This file is auto generated from source, and you will lose your changes next time the website is built.
# Head to the `biomejs/biome` repository, and modify the source code in there.

title: noAccumulatingSpread
description: Learn more about noAccumulatingSpread
---
import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs>
<TabItem label="JavaScript (and super languages)" icon="seti:javascript">
## Summary
- Rule available since: `v1.0.0`
- Diagnostic Category: [`lint/performance/noAccumulatingSpread`](/reference/diagnostics#diagnostic-category)
- This rule is **recommended**, meaning it is enabled by default.
- This rule doesn't have a fix.
- The default severity of this rule is [**warning**](/reference/diagnostics#warning).
## How to configure
```json title="biome.json"
{
	"linter": {
		"rules": {
			"performance": {
				"noAccumulatingSpread": "error"
			}
		}
	}
}

```
## Description
Disallow the use of spread (`...`) syntax on accumulators.

Spread syntax allows an iterable to be expanded into its individual elements.

Spread syntax should be avoided on accumulators (like those in `.reduce`)
because it causes a time complexity of `O(n^2)` instead of `O(n)`.

Source: https://prateeksurana.me/blog/why-using-object-spread-with-reduce-bad-idea/

## Examples

### Invalid

```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => [...acc, val], []);
```

<pre class="language-text"><code class="language-text">code-block.js:2:25 <a href="https://biomejs.dev/linter/rules/no-accumulating-spread">lint/performance/noAccumulatingSpread</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Avoid the use of spread (&#96;...&#96;) syntax on accumulators.</span><br />  <br />    <strong>1 │ </strong>var a = ['a', 'b', 'c'];<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>a.reduce((acc, val) =&gt; [...acc, val], []);<br />   <strong>   │ </strong>                        <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>3 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Spread syntax should be avoided on accumulators (like those in &#96;.reduce&#96;) because it causes a time complexity of &#96;O(n^2)&#96;.</span><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider methods such as .splice or .push instead.</span><br />  <br /></code></pre>

```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {return [...acc, val];}, []);
```

<pre class="language-text"><code class="language-text">code-block.js:2:33 <a href="https://biomejs.dev/linter/rules/no-accumulating-spread">lint/performance/noAccumulatingSpread</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Avoid the use of spread (&#96;...&#96;) syntax on accumulators.</span><br />  <br />    <strong>1 │ </strong>var a = ['a', 'b', 'c'];<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>a.reduce((acc, val) =&gt; &#123;return [...acc, val];&#125;, []);<br />   <strong>   │ </strong>                                <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>3 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Spread syntax should be avoided on accumulators (like those in &#96;.reduce&#96;) because it causes a time complexity of &#96;O(n^2)&#96;.</span><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider methods such as .splice or .push instead.</span><br />  <br /></code></pre>

```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => ({...acc, [val]: val}), {});
```

<pre class="language-text"><code class="language-text">code-block.js:2:26 <a href="https://biomejs.dev/linter/rules/no-accumulating-spread">lint/performance/noAccumulatingSpread</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Avoid the use of spread (&#96;...&#96;) syntax on accumulators.</span><br />  <br />    <strong>1 │ </strong>var a = ['a', 'b', 'c'];<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>a.reduce((acc, val) =&gt; (&#123;...acc, [val]: val&#125;), &#123;&#125;);<br />   <strong>   │ </strong>                         <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>3 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Spread syntax should be avoided on accumulators (like those in &#96;.reduce&#96;) because it causes a time complexity of &#96;O(n^2)&#96;.</span><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider methods such as .splice or .push instead.</span><br />  <br /></code></pre>

```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {return Object.assign([], acc, val);}, []);
```

<pre class="language-text"><code class="language-text">code-block.js:2:32 <a href="https://biomejs.dev/linter/rules/no-accumulating-spread">lint/performance/noAccumulatingSpread</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Orange;">⚠</span></strong> <span style="color: Orange;">Avoid the use of Object.assign on accumulators.</span><br />  <br />    <strong>1 │ </strong>var a = ['a', 'b', 'c'];<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>a.reduce((acc, val) =&gt; &#123;return Object.assign([], acc, val);&#125;, []);<br />   <strong>   │ </strong>                               <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>3 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Spread syntax should be avoided on accumulators (like those in &#96;.reduce&#96;) because it causes a time complexity of &#96;O(n^2)&#96;.</span><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Consider methods such as .splice or .push instead.</span><br />  <br /></code></pre>

### Valid

```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {acc.push(val); return acc}, []);
```

```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => Object.assign(acc, val), []);
```

```js
var a = ['a', 'b', 'c'];
a.reduce((acc, val) => {return Object.assign(acc, val);}, []);
```

## Related links

- [Disable a rule](/linter/#disable-a-rule)
- [Configure the code fix](/linter#configure-the-code-fix)
- [Rule options](/linter/#rule-options)
- [Source Code](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/src/lint/performance/no_accumulating_spread.rs)
- [Test Cases](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/tests/specs/performance/noAccumulatingSpread)

</TabItem>
</Tabs>