Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Insert a word before the file name’s dot extension in JavaScript?
Let’s say the following is our file name −
var actualJavaScriptFileName = "demo.js";
Following is the word to be inserted before the dot extension −
var addValueBetweenFileNameAndExtensions = "programming";
At first, you need to split() the file name on the basis of dot(.) and then to insert a character, you can use the concept of template variables. Following is the code −
Example
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}`)
To run the above program, you need to use the following command −
node fileName.js.
Output
Here, my file name is demo124.js. This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo.js The actual File name=demo.js After adding into the file name= demo-programming.js
Advertisements
