“Js reemplazar” Código de respuesta

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

JavaScript reemplaza todo

const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';

console.log(p.replaceAll('dog', 'monkey'));
// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"

// global flag required when calling replaceAll with regex
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));
// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
Matteoweb

JavaScript reemplazar cadena

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

js reemplaza los caracteres en una cadena

var str = "Original string!";
var str = str.replace("Original", "New");
Poised Penguin

Reemplazar la cadena en TypeScript

var re = /apples/gi; 
var str = "Apples are round, and apples are juicy.";
var newstr = str.replace(re, "oranges"); 
console.log(newstr)
Lucky Louse

Js reemplazar

// siingle replace
"str".replace('s', 'a') // atr
"str".replace(/s|r/, 'a') //ata

// replace all occurrences
"strstr".replace(/s/, 'a') //atratr

// replace with a function
function replacer(match, p1, p2, p3, offset, string) {
  // p1 is nondigits, p2 digits, and p3 non-alphanumerics
  return [p1, p2, p3].join(' - ');
}
let newString = 'abc12345#$*%'.replace(/([^\d]*)(\d*)([^\w]*)/, replacer);
console.log(newString);  // abc - 12345 - #$*%
Anxious Alpaca

Respuestas similares a “Js reemplazar”

Preguntas similares a “Js reemplazar”

Más respuestas relacionadas con “Js reemplazar” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código