उदाहरण
मान लीजिए हमारा फ़ाइल नाम है:
var actualJavaScriptFileName = "demo.js";
वह शब्द जिसे डॉट एक्सटेंशन से पहले जोड़ना है:
var addValueBetweenFileNameAndExtensions = "programming";
सबसे पहले, फ़ाइल नाम को डॉट (.) के आधार पर split() करें और फिर टेम्पलेट लिटरल का उपयोग करके शब्द जोड़ें।
var addValueBetweenFileNameAndExtensions = "programming";
var actualJavaScriptFileName = "demo.js";
console.log("The actual File name=" + actualJavaScriptFileName);
var [fileName, fileExtension] = actualJavaScriptFileName.split('.');
console.log("After adding into the file name=");
console.log(`${fileName}- ${addValueBetweenFileNameAndExtensions}.${fileExtension}`)
उपरोक्त प्रोग्राम चलाने के लिए निम्न कमांड का उपयोग करें:
node fileName.js
आउटपुट
PS C:\Users\Amit\JavaScript-code> node demo.js The actual File name=demo.js After adding into the file name= demo-programming.js