Home / Javascript Tips Generated By ChatGPT / Replacing Substrings in a String in Javascript Use String.replace() to replace parts of a string. Source Code let message = "Hello, world!"; let newMessage = message.replace("world", "JavaScript"); console.log(newMessage); // "Hello, JavaScript!"