How to replace spaces with dashes in JavaScript

Last updated Dec 16, 2017
const text = "codetogo saved me tons of time";

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