let text = "I love you" text = text.replace( / +/g, '_') // replace with underscore ('_') console.log(text) // I_love_you