- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- Perl File Extension
- Insert a node as a child before an existing child in JavaScript?
- Get file extension name in Java
- Java Program to strip a filename of its extension after the last dot
- C# program to get the extension of a file in C#
- Change the file extension in the text column in MySQL?
- How to change file extension in Python?
- Get only the file extension from a column with file names as strings in MySQL?
- How to get the file extension using PowerShell?
- How to get file extension of file as a result of MySQL query?
- How to extract file extension using Python?
- Create temporary file with specified extension suffix in Java
- MySQL query to replace part of string before dot
- Dot notation in JavaScript
- Reading/Writing a MS Word file in PHP

Advertisements