Posted by Arjun Arjun on Saturday 25th July 2020, 1 minute read

Javascript - replaceAll

String.prototype.replaceAll provides an easy way to replace all occurrences of a substring without creating a global RegExp.

const queryString = 'q=query+string+parameters';

// Works, but requires escaping inside regular expressions.
queryString.replace(/\+/g, ' ');
// → 'q=query string parameters'

// Simpler!
queryString.replaceAll('+', ' ');
// → 'q=query string parameters'

I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.