Analog PHP’s str_replace in Javascript

Another analog of PHP’s function that obviously doesn’t work in Javascript is str_replace. Javascript has simple method of String object called “replace()”. Using of this method is very trivial:

var string = "another day on the Earth!";
string.replace('another', 'new');

There is one problem – this method replaces only first match it can find. To use ability of replacing many mathces see replace_all() function in javascript.

Books to read

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">