题解 | #文件扩展名#
文件扩展名
https://www.nowcoder.com/practice/01ca4c6aa14249c2911f89baba9dc023
{"html":"<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n </head>\n <body>\n \n <script>\n const _getExFilename = (filename) => {\n // 补全代码\n const index = filename.lastIndexOf('.')\n const ext = filename.slice(index)\n return ext\n }\n </script>\n </body>\n</html>","css":"","js":""}
- 通过字符串的实例方法lastIndexOf方法,从字符串的右边开始检索 '.' 字符,获取第一个检测到的字符的索引
- 调用字符串切片方法slice从检测到的索引的位置开始切到末尾即文件扩展名