JavaScript Replace() Method Last Updated : 30 May, 2023 Summarize Comments Improve Suggest changes Share 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 String Methods 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 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 Like