JavaScript replaceAt() Method Last Updated : 06 Mar, 2023 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 index arguments, and use the JavaScript splice() method to remove the character at the specified index and insert the new character in its place. We declare this method by specifying it in String.prototype. Syntax: string.replaceAt(replace_position, replace_char); Parameters: This method accepts two parameters. replace_position: It is the value that we want to replace in the existing string.replace_char: It is the new value that is to be put in the place of replace_position. Return Value: This method returns a new string where the desired values have been replaced. Example: Input: str = hello world replace_position = 2 replace_char = k Output: hello world Input: str = Geeks for geeks replace_position = 4 replace_char = d Output: Geeks for geeks Here is an example of how this function could be defined: Example 1: JavaScript // JavaScript program to demonstrate replaceAt() method String.prototype.replaceAt = function(index, replacement) { return this.substr(0, index) + replacement + this.substr(index + replacement.length); } let str = "Hello World"; let replace_position = 1; let replace_char = "a"; let newStr = str.replaceAt(replace_position,replace_char); console.log(newStr); Output: Hallo World Example 2: JavaScript // JavaScript program to demonstrate replaceAt() method String.prototype.replaceAt = function(index, replacement) { return this.substr(0, index) + replacement + this.substr(index + replacement.length); } let str = "Geeks for geeks"; let replace_position = 4; let replace_char = "d"; let newStr = str.replaceAt(replace_position,replace_char); console.log(newStr); Output: Geeks for geeks We have a complete list of Javascript Strings methods, to check those please go through Javascript String Complete reference article. Comment More infoAdvertise with us Next Article JavaScript String Methods V vinaypinjala Follow Improve Article Tags : Technical Scripter JavaScript Web Technologies Technical Scripter 2022 javascript-string JavaScript-Methods +2 More Similar Reads JavaScript Replace() Method 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. searchV 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 Java HashMap replace() Method The replace() method of the HashMap class in Java is used to replace the value associated with a specific key if the key is already present in the map.Note: If the key does not exist, the method does nothing and the map remains unchanged.Example 1: This example demonstrates replacing the value of an 3 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 Like