split() 方法使用指定的分隔符字符串将一个String对象分割成字符串数组,以将字符串分隔为子字符串,以确定每个拆分的位置。
var str = 'The quick brown fox jumps over the lazy dog.';
var words = str.split(' ');
console.log(words[3]);
// expected output: "fox"
var chars = str.split('');
console.log(chars[8]);
// expected output: "k"
var strCopy = str.split();
console.log(strCopy);
// expected output: Array ["The quick brown fox jumps over the lazy dog."]
toLowerCase()方法返回转换为小写的调用字符串值
toUpperCase 则相反
String.charAt(index) 与 String[index]效果一致
**
String.prototype.charCodeAt()
**
就是返回字符串中下标单个数值 对应的编码表的10进制表示数值
方法返回0到65535之间的整数,表示给定索引处的UTF-16代码单元
延伸:在node后端中使用 fs.readFile()其中有指定方式读取是 utf-8
const sendHtml = (path, response) => {
let options = {
encoding:"utf-8"
}
fs.readFile(path, options, (error, data) => {
response.send(data)
})
}
const index = {
method: "get",
path: "/",
func:(request, response) => {
let path = "template/blog_index.html"
sendHtml(path, response)
}
}
**
String.fromCharCode()
**
fromCharCode() 可接受一个指定的 Unicode 值,然后返回一个字符串。
注意:该方法是 String 的静态方法,字符串中的每个字符都由单独的 Unicode 数字编码指定。使用语法: String.fromCharCode()。
var n = String.fromCharCode(65)
// A