“Substitua em JavaScript” Respostas de código

Substituindo caracteres em String javascript

var myStr = 'this,is,a,test';
var newStr = myStr.replace(/,/g, '-');

console.log( newStr );  // "this-is-a-test"
Exuberant Emu

JavaScript Substitua string

var str = "JavaScript replace method test";
var res = str.replace("test", "success");  
//res = Javscript replace method success
Batman

JavaScript Substitua

var res = str.replace("find", "replace");
Friendly Hawk

JavaScript Texto Substitua

let text = "I     love you"
text = text.replace( / +/g, '_') // replace with underscore ('_')

console.log(text) // I_love_you
Asiful Islam Sakib

String.Rplace JavaScript

//Replace the first match in a string
//If you wish to replace all matches, use the replaceAll() method.

var str = "JavaScript replace method test";
var res = str.replace("test", "success");  
//res = Javscript replace method success
Cupboard Steak

Substitua em JavaScript

var str = "Please locate where 'locate' occurs!";

str.replace("locate", "W3Schools"); //replace only replace first match from string
str.replace(/LOCATE/i, "W3Schools"); // i makes it case insensitive
str.replace(/LOCATE/g, "W3Schools"); // g replace all matches from string rather than replacing only first
Dangerous Duck

Respostas semelhantes a “Substitua em JavaScript”

Perguntas semelhantes a “Substitua em JavaScript”

Mais respostas relacionadas para “Substitua em JavaScript” em JavaScript

Procure respostas de código populares por idioma

Procurar outros idiomas de código