数组,字符串方法总结 Unicode 数字

String.prototype.charCodeAt(index)

就是返回字符串中下标单个数值  对应的编码表的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

 

Array.prototype.reverse()

reverse() 方法将数组中元素的位置颠倒,并返回该数组。数组的第一个元素会变成最后一个,数组的最后一个元素变成第一个。该方法会改变原数组 

Array.prototype.map()

map() 方法创建一个新数组,其结果是该数组中的每个元素都调用一个提供的函数后返回的结果。

const array1 = [1, 4, 9, 16];

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(map1);
// expected output: Array [2, 8, 18, 32]

 

posted @ 2019-11-10 10:53  容忍君  阅读(512)  评论(0)    收藏  举报