ES10 bigInt
// Flat flatMap()
flat 拉平数组,去除空项
const arr = [1,2,3,[4,5]]
const arr1 = [1,2,3,[4,5,[6]]]
console.log(arr.flat())
console.log(arr1.flat(num))
console.log(arr1.flat(Infinity))
const arr1 = [1,2,3,4]
console.log(arr1.map(x=>[x2]))
console.log(arr1.flatMap(x=>[x2]))
//Object.formEntries() => 对象自身可枚举属性 for…in
const map = new Map([“name”,”-灯”], [“address”,”bejing”]);
console.log(Object.formEntries(map))
console.log(Object.entries);Ide
String.prototype.matchAll 返回包含所有匹配正则表达式及分组捕获迭代器
const str = “yideng xuetang xuetang”;
const reg= /xue*/g
while(matches = reg.exec(str)!== null) {
console.log(${matches[0]}-${reg.lastIndex}
)
}
let matches2 = str.matchAll(reg)
const reg = /y(i)(deng(\d?))/g
// trimStart // trimEnd
// Symbol.prototype.description
const sym = Symbol(“描述”)
console.log(String(sym))
console.log(sym.description);
Catch 参数可以省略
// 之前
try {
} catch(e) {
}
try {
} catch{
}
行分割符和段分割符号
JSON.parse JSON是ECMAScript的一个子集
// 草案 解决一个问题
const json = ‘{“name”: “yideng”\nxuetang}’
console.log(json)
JSON.parse(json);
JSON.stringify()
字符U+D800 到 U+DFFF处理
U+2028 行分隔符 U+2029 段分割符
JSON.stringify(‘\UDEAD’);
Array.prototype.sort()
小于10 插入排序 快速排序 O<n^2>
新的v8 TimSort() n(nlogn)
const arr = [
{name: ‘w’, age:18}
{name: ‘d’, age:1}
{name: ‘yideng ‘, age:8}
{name: ‘x’, age:108}
{name: ‘j’, age:198}
]
arr.sort((a,b)=> a.age-b.age);
Function.string()
Object.prototype.toString();
function /1213/ foo /123/() {
}
console.log(foo.toString())
// BigInt 任意进度整数 第七种基本数据类型
2^53-1
let num = 1n;
// 标准化的globalThis 对象
const getGlobal = function () {
if(typeof self != “undefined) return self;
if(typeof window != “undefined) return window;
if(typeof gloabal != “unefined”) reutrn global;
throw new Error();
}
// 在任何属性中打印this
consolelog(globalThis)