1const file = 'test.jpg';
2const filename = file.split('.').slice(0, -1).join('.');
1// using string methods only
2filename.substring(0, filename.lastIndexOf('.')) || filename
3
4// using both string & array methods
5filename.split('.').slice(0, -1).join('.')
6