关于JavaScript字符串的所有属性和方法
字符串对象有一个静态方法,String.fromCharCode() ,用于从Unicode字符序列中创建一个字符串表示。这里我们使用ASCII码建立一个简单的字符串
String.fromCodePoint(70, 108, 97, 118, 105, 111) //'Flavio'
你也可以使用八进制或十六进制的数字。
String.fromCodePoint(0x46, 0154, parseInt(141, 8), 118, 105, 111) //'Flavio'
这里描述的所有其他方法都是实例方法:在一个字符串类型上运行的方法。
实例方法
字符串提供了一些你可以使用的独特方法。
charAt(i)charCodeAt(i)codePointAt(i)concat(str)endsWith(str)includes(str)indexOf(str)lastIndexOf(str)localeCompare()match(regex)normalize()padEnd()padStart()repeat()replace(str1, str2)search(str)slice(begin, end)split(separator)startsWith(str)substring()toLocaleLowerCase()toLocaleUpperCase()toLowerCase()toString()toUpperCase()trim()trimEnd()trimStart()valueOf()