String.prototype.replace()
String.prototype.replace() is a JavaScript method in the String category. Replaces matched substring with a new substring. The syntax is str.replace(pattern, replacement). A typical example: "Hello World".replace("World", "JS") // "Hello JS". Another practical use — Replace all occurrences: const text = 'Hello World, Hello Everyone' const result = text.replaceAll('Hello', 'Hi') console.log(result) // 'Hi World, Hi Everyone' Its time complexity is O(n), which matters when it runs over large inputs. The TypeScript signature is (searchValue: string | RegExp, replaceValue: string | ((substring: string, ...args: any[]) => string)): string. Common pitfall — Only replaces first match without global. "a-a-a".replace("-", "+") returns "a+a-a" — only the first match. Use replaceAll() or /g flag for all occurrences. A close sibling is String.prototype.charAt(), which returns the character at the specified index. A close sibling is String.prototype.charCodeAt(), which returns the Unicode value of the character at the specified index. A close sibling is String.prototype.concat(), which concatenates strings together.