How to replace spaces with dashes in JavaScript

Strings
By Jad Joubran · 
Last updated Dec 16, 2017
const text = "codetogo saved me tons of time";

text.replace(/ /g, "-");
codetogo-saved-me-tons-of-time