字符串``模板,和方法

  1. 新方法 startsWith / endsWith
  2. 模板字符串
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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容