Knowledge Walls
Laya
Hyderabad, Andhra Pradesh, India
String.prototype.replace() Method in String Class of Javascript Syntax with Examples
2113 Views
Usage 
string replace method matches the string with specified string or regular expression pattern and replace the matches with new string finally returns the replaced string.

Note:
  1. replace method performs case sensitive matches.
  2. When matching with string it replaces first match on the data by new string.
  3. When matching with pattern can possible to replace all matches in a string.
Syntax
[string] string.replace([search_string | pattern],[replace_with]);
Example
var data = "My name is Javascript. Javascript is a scripting language of client browsers.";
document.write(data.replace("Javascript","js"));
document.write("<br />");

document.write(data.replace(/javascript/i,"js"));
document.write("<br />");

document.write(data.replace(/Javascript/g,"js"));
document.write("<br />");
Output 
My name is js. Javascript is a scripting language of client browsers.
My name is js. Javascript is a scripting language of client browsers.
My name is js. js is a scripting language of client browsers.
Try it 
Best Lessons of "Javascript Syntax with Examples"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details