In javascript how it's possible to replace all occurrence of &,<,> in a string
I tried this
var str="<>&";
str.replace("&","&").replace("<","<").replace(">",">");
but not able to change even first occurrence
In javascript how it's possible to replace all occurrence of &,<,> in a string
I tried this
var str="<>&";
str.replace("&","&").replace("<","<").replace(">",">");
but not able to change even first occurrence
The easiest would be to use a regular expression with g flag to replace all instances:
str.replace(/foo/g, "bar")
This will replace all occurrences of foo with bar in the string str. If you just have a string, you can convert it to a RegExp object like this:
var pattern = "foobar",
re = new RegExp(pattern, "g");