includes(字符串中是否包含某個字符,第二個參數(shù)表示從第幾個字符開始):
用法:String.includes(str,index)
返回值:Boolean
var str = "hello world!"
console.log(str.includes("hello")); // true
console.log(str.includes("hello",2)); // false
startsWith(某個字符是否處于該字符串之首,第二個參數(shù)表示從第幾個字符開始):
用法:String.startsWith(str龄糊,index)
返回值:Boolean
var str = "hello world!"
console.log(str.startsWith("h")); // true
console.log(str.startsWith("h",2)); // false
endsWith(某個字符是否處于該字符串之尾,第二個參數(shù)表示從第幾個字符開始):
用法:String. endsWith(str顷歌,index)
返回值:Boolean
var str = "hello world!"
console.log(str.endsWith("!")); // true
console.log(str.endsWith("!",2)); // false
console.log(str.endsWith("!",str.length)); // true