Here you can see, first 'one' is replaceed by 'XXX' and second 'one' still there. When you run the code, above script will return "XXX two three one five nine". But, if a string contain repeated words, replace() method change the first occurrence of the string only. ![]() ![]() ![]() The replace() method in JavaScript searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
0 Comments
Leave a Reply. |