题解 | #文件扩展名#
文件扩展名
http://www.nowcoder.com/practice/01ca4c6aa14249c2911f89baba9dc023
02_文件扩展名
本题考点:lastIndexOf、slice
根据题目要求,返回字符串参数的扩展名,核心步骤有:
- 首先通过lastIndexOf获取最后一个"."符号的位置
- 然后通过slice截取index(包括)之后的字符串
参考答案:
const _getExFilename = (filename) => {
let index = filename.lastIndexOf('.')
return filename.slice(0, index) && index !== -1 ? filename.slice(index) : ''
}