字符串``模板,和方法

2020-03-07  本文已影响0人  增商
  1. 新方法 startsWith / endsWith
  2. 模板字符串
let str = "https://imycode.cn";
      if (str.startsWith("http://")) {
        console.log("普通网址");
      } else if (str.startsWith("https://")) {
        console.log("加密地址"); //加密地址
      } else if (str.startsWith("git://")) {
        console.log("git地址");
      } else {
        console.log("其它网址");
      }

endsWith
邮箱附件图标,根据文件判断什么类型的扩展名判断

   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

现在


image.png
上一篇 下一篇

猜你喜欢

热点阅读