replace() using strings in JS
replace() using strings in JS
<!DOCTYPE html>
<html>
<head>
<title>Test page</title>
<script type="text/javascript">
//replace will basically search for the given word and replace it with required word
var str= "This a great platform for learning html , css and javascript!!!";
var b= str.replace("html" , "cool html ");
console.log(b);
var newstr= "This a great platform for learning great html , css and javascript!!!";
var x=newstr.replace("great","GREAT");
document.write(x);
document.write("<br><br><br>")
/*note that it has only repaced one "great" expression.
To replace it everywhere we need to use global variables*/
var y=newstr.replace( /great/g , "HIGHLY AWESOME");
document.write(y);
</script>
</head>
<body>
<h1></h1>
</body>
</html>
HERE IS THE OUTPUT :
Comments
Post a Comment
I WOULD APPRECIATE IF YOU LEAVE A COMMENT OR YOUR FEEDBACK HERE !!!