Reemplazar caracteres en String JavaScript
var myStr = 'this,is,a,test';
var newStr = myStr.replace(/,/g, '-');
console.log( newStr ); // "this-is-a-test"
Exuberant Emu
var myStr = 'this,is,a,test';
var newStr = myStr.replace(/,/g, '-');
console.log( newStr ); // "this-is-a-test"
var str = "JavaScript replace method test";
var res = str.replace("test", "success");
//res = Javscript replace method success
var str = "Original string!";
var str = str.replace("Original", "New");
function replaceAll(str, find, replace) {
var escapedFind=find.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
return str.replace(new RegExp(escapedFind, 'g'), replace);
}
//usage example
var sentence="How many shots did Bill take last night? That Bill is so crazy!";
var blameSusan=replaceAll(sentence,"Bill","Susan");
// Replace All
str = str.replace(/_/g, ' ');
function spinWords(pw){
let a = ''
if(pw.length <= 5){
a +=pw.split("").reverse()
console.log(a.replaceAll(',' , ''))
}else {
console.log("olá")
}
}
let hey = "hello";
spinWords(hey) // olleh