replace(oldToken, newToken);

The replace() method is similar to the add()method but instead of adding a class with the original you change the original class. Unlike the add method once you replace an array element or CSS class there’s no way to bring back the original. It uses two properties, the first being the old token that you’re going to replace and the second being your new token.

const dream = "I want to be a basketball player";

// replace the first b with c
let result = dream.replace('basketball player', 'computer programmer');
console.log(result);

// The output would be "I want to be a computer programmer"