JavaScript String replace()

The replace() method returns a new string with the specified string/regex replaced.

Example

const message = "ball bat";

// replace the first b with c let result = message.replace('b', 'c');
console.log(result); // Output: call bat