मान लीजिए हमारे पास निम्नलिखित स्ट्रिंग है:
var sentence = "My Name is David Miller I live in AUS";
उपरोक्त स्ट्रिंग में स्पेस को अंडरस्कोर से बदलने के लिए, split() के साथ join() का उपयोग करें।
उदाहरण
निम्नलिखित कोड है:
var sentence = "My Name is David Miller I live in AUS";
var withUnderscore = sentence.split(' ').join('_');
console.log("The actual result=");
console.log(sentence);
console.log("After replacing the space with underscore=");
console.log(withUnderscore);
उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्नलिखित कमांड का उपयोग करना होगा:
node fileName.js
यहां, मेरा फ़ाइल नाम demo250.js है।
आउटपुट
यह कंसोल पर निम्नलिखित आउटपुट देगा:
PS C:\Users\Amit\javascript-code> node demo250.js The actual result= My Name is David Miller I live in AUS After replacing the space with underscore= My_Name_is_David_Miller_I_live_in_AUS