0
点赞
收藏
分享

微信扫一扫

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

禾木瞎写 2022-04-16 阅读 73
es6

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 条评论