Javascript — string replace all without Regex

I have been work­ing with Node.js and Server­less heav­i­ly. It’s the first time I’ve real­ly spent seri­ous amount of time in Javascript, and I’m mak­ing plen­ty of begin­ner mis­takes and learn­ing lots.

One pecu­liar thing I find in Javascript is that String.replace only replaces the first instance of the sub­string, unless you use a Regex. For­tu­nate­ly I found a clever lit­tle pat­tern to do this with­out Regex : String.split(subString).join(replaceString).

So sup­pose you want to remove the hyphen (-) in an AWS region name, you could write:

let region = ‘eu-west-1’;

let region­No­Hy­phen = region.split(‘-’).join(”);

Much eas­i­er than using Regex, wouldn’t you agree?