美文网首页
字符串``模板,和方法

字符串``模板,和方法

作者: 增商 | 来源:发表于2020-03-07 15:37 被阅读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

相关文章

网友评论

      本文标题:字符串``模板,和方法

      本文链接:https://www.haomeiwen.com/subject/gnucdhtx.html