编辑
核心代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>返回文件扩展名</title> </head> <body> <!-- 请补全JavaScript代码,要求以字符串的形式返回文件名扩展名,文件名参数为"filename"。 --> <script>const _getExFilename = (filename) => { // 补全代码 let lastindex = filename.lastIndexOf('.') return filename.slice(0, lastindex) && lastindex !== -1 ? filename.slice(lastindex) : ''</script> </body> </html>
总结
找到.后面的值进行截取即可
