javascript remove extension from filename 1

javascript remove extension from filename

const file = 'test.jpg';
const filename = file.split('.').slice(0, -1).join('.');

Here is what the above code is Doing:
1. We’re creating a variable called file and assigning it the value of test.jpg.
2. We’re creating a variable called filename and assigning it the value of the file variable, but we’re using the split() method to split the string into an array of strings.
3. We’re using the slice() method to remove the last item in the array.
4. We’re using the join() method to join the array back into a string.

Similar Posts