Dev Helpers

JavaScript / Strings

Replace every occurrence

Dev Helpers · October 10, 2026

Replacing just the first delimiter leaves mixed formatting in an identifier. replaceAll makes the intended scope explicit.

Worked example

console.log("red green red".replaceAll("red", "blue"));

Result

blue green blue

Implementation notes

A literal search string treats punctuation as ordinary text. If the term becomes a regular expression, both escaping and the global flag become part of the contract.

Try it yourself

Include two adjacent delimiters and an input with no delimiter.

Open the JavaScript example →

Editorial date October 10, 2026 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.