startswith()、endswith()和trim()方法

阅读 73

2022-04-16

startswith() :字符串以什么开头,返回布尔值

       let str="hello world"
        let result=str.startsWith("hello")
        console.log(result)//true

endswith():字符串以什么结尾 ,返回布尔值

 let str="hello world"
  let r1=str.endsWith("ld")
        console.log(r1)//true

trim():清除字符串前后空格的

let str=" hello world"
		console.log(str.trim())

有时候写让用户填写密码或者是用户名是可以使用,提升用户的体验性

        let str=" hello world"
        console.log(str.trim()=="hello world")//true

 

精彩评论(0)

0 0 举报