ES6 determines what the string starts or ends with

The startsWith() method determines whether the string starts with the characters of the specified string, and returns true or false.
The syntax of endsWith() method and startsWith() method is the same, but endsWith() method searches from the end of the string.

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;

Guess you like

Origin blog.csdn.net/m0_47402657/article/details/106505011