String replace dots with underscores

JS
S
JavaScript

Replaces dot characters with underscores in strings. Useful for converting domain names or IP addresses to valid identifiers or filenames.

1if (key.indexOf('.') > -1 || key.indexOf(':') > -1){
2  key = key.replace(/\./g,'_')
3  key = key.replace(/\:/g,'_')
4}

Created on 3/1/2018