The term “extension” refers to the suffix at the end of a file name describing its sort of file. For instance, the file extension is .TXT in the file name “text.txt”. The file is a text document. Other examples are the.docx file extension, which is used for Microsoft Word documents, and the PSD file extension, which is the default for Photoshop documents.
Examining the file’s extension allows an operating system to determine which application to read, print, or edit a particular file. Because each operating system in the setup has a default mapping between a file extension and a specific program, it can do this function.
Use split() and slice() method
The split method of a string object is used to split a string into an array of substrings and return the new array.
- Separator: (Optional) Specifies the character, or regular expression, to use to split the string. If omitted, the entire string is returned (an array with only one item).
- limit: (Optional) An integer specifying the number of splits, items after the division limit will not be included in the array.
string.slice( begin slice [, endSlice] );
- startSlice: The index at which the extraction should begin.
- endSlice: The index where the program should stop the extraction. Slice extracts to the end of the string if it is omitted.
After knowing about the method to use this way, let’s see the example below to understand more about how to do it.
var file = 'number.txt'; var filename = file.split('.').slice(0, -1).join('.'); console.log(filename);
First, we separate the filename from the file extension using the split method where the “.” then we use the slice complex method to remove the extension. The program will return an array with a string named file name, so we use the join method to get that value.
Refer to the index position with 
Like the above method, we use the split method to split into two strings, filename and file extension. But in this way, we use  to point to the string with index 0, and we can get the string filename and print it to the console.
var file = 'number.txt'; var filename = file.split('.'); console.log(filename);
So we obtained the filename string of the file and printed it to the screen. Hope it helps you.
Maybe you are interested:
Name of the university: PTIT