const file = 'test.jpg';
const filename = file.split('.').slice(0, -1).join('.');
// using string methods only
filename.substring(0, filename.lastIndexOf('.')) || filename
// using both string & array methods
filename.split('.').slice(0, -1).join('.')
let file = "yourFileName.txt";
let filename = file.split('.')[0]