JavaScript Replace() Method Last Updated : 30 May, 2023 Comments Improve Suggest changes Like Article Like Report The replace() method in JavaScript is used to search a string for a value or any expression and replace it with the new value provided in the parameters. The original string is not changed by this method. Syntax: string.replace(searchVal,newVal) Parameter: This method accepts two parameters. searchVal: It is the value that we want to replace in the existing stringnewVal: It is the new value that is to be put in the place of searchVal. Return Value: This method returns a new string where the desired values have been replaced. Example 1: In this example, we will use the replace() method to replace a character from the original string but the replace method here does not replace the characters which are in lowercase. JavaScript let stringReplace = "Geeks for geeks is a great platform to learn Javascript"; let result = stringReplace.replace(/Geeks/, "GFG"); console.log('New string: ' + result); OutputNew string: GFG for geeks is a great platform to learn JavaScript Example 2: In this example, the replace() method replaces the words completely irrespective of their case. JavaScript let stringReplace = "Geeks for Geeks is a great platform to learn Javascript"; let result = stringReplace.replace(/Geeks/gi, "GFG"); console.log('New string: ' + result); OutputNew string: GFG for GFG is a great platform to learn JavaScript Comment More infoAdvertise with us Next Article JavaScript Replace() Method N Naman_Garg Follow Improve Article Tags : JavaScript Web Technologies javascript-functions Similar Reads JavaScript replaceAt() Method The replaceAt() method is useful for removing the character at a given place. Unfortunately, the replaceAt() method is not a built-in method in JavaScript. It would need to be defined by the user in order to use it. One possible implementation of a replaceAt() function could take a string and two in 2 min read JavaScript string replace() Method JavaScript replace() method is used for manipulating strings. It allows you to search for a specific part of a string, called a substring, and then replace it with another substring. What's great is that this method doesn't alter the original string, making it ideal for tasks where you want to maint 5 min read JavaScript String replaceAll() Method The replaceAll() method in JavaScript is used to replace all occurrences of a specified substring or pattern with a new substring. The replaceAll() method does not change the original string.JavaScript's replaceAll() method used for replacing all instances of a specified substring or pattern within 3 min read JavaScript String Methods JavaScript strings are the sequence of characters. They are treated as Primitive data types. In JavaScript, strings are automatically converted to string objects when using string methods on them. This process is called auto-boxing. The following are methods that we can call on strings.slice() extra 11 min read JavaScript Symbol replace Property JavaScript Symbol replace the property is used to determine the method that replaces the matched substring of a string. This function is called by the String replace() method. Syntax: [Symbol.replace](string) Parameters: It accepts single parameter "String". Return value: It will return a new string 2 min read jQuery replaceAll() Method The replaceAll() method is an inbuilt method in jQuery that is used to replace selected elements with new HTML elements. Syntax: $(content).replaceAll(selector)Parameters: This method accepts two parameters as mentioned above and described below: content: It is the required parameter that is used to 1 min read Collect.js replace() Method The replace() method is used to replace the elements of the original collection that match the given string or numeric keys. If the key given in the object matches with a key in the collection, then its value is replaced, otherwise, if the key does not match, then it is added to the collection. Synt 1 min read HTML DOM replaceWith() Method The replaceWith() method replaces the node in the children list of its parent with a set of Node or DOMString objects. DOMString objects are equivalent to Text nodes. Here, the One Child element is replaced by the Other Child element. Syntax: ChildNode.replaceWith(Node); Parameters: ChildNode: The C 1 min read HTML DOM TokenList.replace() Method The replace() method in HTML DOM is used to replace or change an old token with a new one in a DOM TokenList Object. Syntax: domtokenlist.replace(old, new) Parameter Values: It contains two values: old: It is a required parameter, that specifies the name of the token that would be replaced. new: It 1 min read What is jQuery's Equivalent of str_replace in JavaScript? In JavaScript, the equivalent of PHPâs str_replace is the replace method of strings. While jQuery doesn't offer a direct str_replace equivalent, JavaScriptâs replace and replaceAll methods can be used effectively.1. Replace a Single Instance with replaceThis method replaces the first occurrence of a 1 min read Like