startsWith()方法确定字符串是否以指定字符串的字符开头,返回true或false。
endsWith()方法和startsWith()方法的语法都是一样的,不过endsWith()方法是从字符串的末尾开始查找。
let str = "https://C:/Users/2/1.png";
console.log(str.startsWith("https://"))// true;
console.log(str.startsWith("http://"))// false;
console.log(str.endsWith(".jpg"))// false;
console.log(str.endsWith(".png"))// true;