- 新方法 startsWith / endsWith
- 模板字符串
let str = "https://imycode.cn";
if (str.startsWith("http://")) {
console.log("普通網(wǎng)址");
} else if (str.startsWith("https://")) {
console.log("加密地址"); //加密地址
} else if (str.startsWith("git://")) {
console.log("git地址");
} else {
console.log("其它網(wǎng)址");
}
endsWith
郵箱附件圖標(biāo),根據(jù)文件判斷什么類型的擴(kuò)展名判斷
let fil = "1.txt";
if (fil.endsWith(".txt")) {
console.log("文本文件");
} else if (fil.endsWith(".exe")) {
console.log("exe安裝文件");
} else if (fil.endsWith(".app")) {
console.log("app文件");
} else if (fil.endsWith(".jpeg")) {
console.log("圖片");
} else {
console.log("不明文件");
}
模板字符串
以前是用加號拼接
image.png
現(xiàn)在
image.png

