web-profile

javascript string replace

<script>
var old_str = 'pizza is good';
var new_str = old_str.replace('good', 'awesome'); // replace() does not change the original string, it only returns the new value
alert(new_str); // returns 'pizza is awesome'
alert(old_str); // returns 'pizza is good', old value is not changed
</script>

Leave a Reply

Your email address will not be published.