Skip to content

no-string-concat-in-loop

Prefer collecting string fragments over repeatedly accumulating a growing string inside a loop.

Why

Repeatedly rebuilding a growing string can copy all prior content on each iteration, making total work grow quadratically.

Fix

Consider collecting fragments and joining once; preserve intermediate observations and coercion timing, and measure hot paths.

Examples

Before — flagged Do not rebuild a growing string in a loop
src/render.ts
let output = "";
for (const item of items) {
output = `${output}${item}`;
}
After — preferred Join collected fragments after the loop
src/render.ts
const parts = [];
for (const item of items) {
parts.push(item);
}
const output = parts.join("");