https://leetcode.com/problems/defanging-an-ip-address/
var defangIPaddr = function(address) {
let defangStr = '';
for (let i = 0; i < address.length; i++) {
if (address[i] === '.') {
defangStr += '[.]';
} else {
defangStr += address[i]
}
}
return defangStr;
};
there are some convenient api
var defangIPaddr = function(address) {
return address.split('.').join('[.]');
};
var defangIPaddr = function(address) {
return address.replace(/\./g,"[.]");
};