字符串``模板,和方法

  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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。