If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
replace() method किसी String में दी गयी value / regular expression को search करके specified value से replace करके new String return करता है। हालांकि इससे Original String में कोई changes नहीं आते हैं।
string.replace(searchValue: string, replaceValue: string);
string | required : यह String variable है जिसमे हमें value को search करना है।
searchValue | required : value जो String में search करनी है।
replaceValue | required : value जो String में replace करनी है।
Return Value : यह method एक new String return करता है , जहाँ search की गयी value को replaced / new value से replace कर दिया जाता है।
File : js_string_replace.html
<!DOCTYPE html>
<html>
<body>
<script>
let str = "Visit google.com to learn PHP , JavaScript , jQuery etc.";
document.write(str.replace("google.com", "learnhindituts.com"));
document.write("<br> Original String : " + str);
</script>
</body>
</html>
Visit learnhindituts.com to learn PHP , JavaScript , jQuery etc. Original String : Visit google.com to learn PHP , JavaScript , jQuery etc.
❕ Important :
अगर search value String में नहीं मिलती तो original string ही return होती है।
empty String के लिए replace() method call करने पर कुछ भी return नहीं होता है।
replace value provide न करने पर undefined से replace हो जाता है।
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook