You need a /g
on there, like this:
var textTitle = "this is a test";_x000D_
var result = textTitle.replace(/ /g, '%20');_x000D_
_x000D_
console.log(result);
_x000D_
You can play with it here, the default .replace()
behavior is to replace only the first match, the /g
modifier (global) tells it to replace all occurrences.