References
String.replace()
Leírás
Az adott String példánynál cseréli az első paraméterbe írt értéket a másikba írt értékre, és elfogad reguláris kifejezéseket is.
Szintaxis
replace(pattern, replacement)
Példa
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?'
console.log(p.replace('dog', 'monkey'))
// Expected output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"
const regex = /Dog/i
console.log(p.replace(regex, 'ferret'))
// Expected output: "The quick brown fox jumps over the lazy ferret. If the dog reacted, was it really lazy?"