# no-array-concat-in-loop πŸ“ Disallow array accumulation with `Array#concat()` in loops. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). `Array#concat()` creates a new array every time it is called. When an accumulator is reassigned with `.concat()` on every loop iteration, each iteration copies everything accumulated so far, which can make the loop quadratic in the total number of accumulated items. Use `Array#push()` inside the loop when each chunk is an array, or collect the nested arrays and flatten them once outside the loop. This rule intentionally only reports local `let` and `var` variables initialized to an empty array literal. It does not try to infer arbitrary array-like values or custom `.concat()` methods. This rule does not provide an autofix. Replacing `.concat()` with `.push()` can change observable behavior when the old array is aliased, and `.concat()` has argument-spreading semantics that are not always equivalent to `push(...value)`. ## Examples ```js // ❌ let result = []; for (const chunk of chunks) { result = result.concat(chunk); } ``` ```js // βœ… const result = []; for (const chunk of chunks) { result.push(...chunk); } ``` ```js // βœ… const result = chunks.flat(); ``` ```js // βœ… let result = []; for (const chunk of chunks) { result = other.concat(chunk); } ```