includes(),startWith(),endsWith()
传统上,Javascript只有indexof方法,可以确定一个字符串是否包含在另一个字符串中,
ES6中,提供了三种新方法:
-includes():返回布尔值,表示是否找到了参数字符串。
-startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
-endsWith():返回布尔值,表示参数字符串是否在原字符串的尾部。
repeat()
repeat方法返回一个新字符串,表示将原字符串重复n次。
padStart(),padEnd()
ES2017引入了字符串补全长度的功能。如果某个字符串不够指定长度,会在头部或尾部补全。padStart()用于头部补全,padEnd()用于尾部补全。
trimStart(),trimEnd()
ES2019 对字符串实例新增了trimStart()
和trimEnd()
这两个方法。它们的行为与trim()
一致,trimStart()
消除字符串头部的空格,trimEnd()
消除尾部的空格。它们返回的都是新字符串,不会修改原始字符串。