The Ultimate Way to Slugify a URL String in JavaScript

Turn “this URL-optimized string” into “this-url-optimized-string” easily with this snipped of JavaScript code.