ES6:includes(), startsWith(), endsWith()

includes(), startsWith(), endsWith()

  • includes():返回布尔值,表示是否找到了参数字符串。
  • startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
  • endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
  • let s = 'Hello world!';
    
    s.startsWith('Hello') // true
    s.endsWith('!') // true
    s.includes('o') // true
let s = 'Hello world!';

s.startsWith('world', 6) // true
s.endsWith('Hello', 5) // true
s.includes('Hello', 6) // false

上面代码表示,使用第二个参数n时,endsWith的行为与其他两个方法有所不同。它针对前n个字符,而其他两个方法针对从第n个位置直到字符串结束。 

{...{marginBottom: this.marginBottom + 'px',...this.newStyle}} this.newStyle 覆盖前面的this.marginBottom

 


版权声明:本文为qq_25103439原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。