You have the following options:
var text = "this is some sample text that i want to replace and this i WANT to replace as well.";_x000D_
var new_text = text.replace('want', 'dont want');_x000D_
// new_text is "this is some sample text that i dont want to replace and this i WANT to replace as well"_x000D_
console.log(new_text)
_x000D_
var text = "this is some sample text that i want to replace and this i WANT to replace as well.";_x000D_
var new_text = text.replace(/want/g, 'dont want');_x000D_
// new_text is "this is some sample text that i dont want to replace and this i WANT to replace as well_x000D_
console.log(new_text)
_x000D_
var text = "this is some sample text that i want to replace and this i WANT to replace as well.";_x000D_
var new_text = text.replace(/want/gi, 'dont want');_x000D_
// new_text is "this is some sample text that i dont want to replace and this i dont want to replace as well_x000D_
console.log(new_text)
_x000D_
More info -> here