fxxqq / 6fedcom.github.io

frank的前端养成记(hexo博客)
https://6fed.com
22 stars 5 forks source link

javascript截取文件名的后缀 #112

Open fxxqq opened 6 years ago

fxxqq commented 6 years ago
const fileName="text.png";

//带.的格式
let fileFormat=fileName.substring(fileName.lastIndexOf('.'))

// 不带.的格式
let fileFormat2=fileName.substring(fileName.lastIndexOf('.')+1);
console.log(fileFormat,fileFormat2)

image