ES12在垃圾回收之前执行一个异步操作
const finalRegistyr =new FinalizationRegistry((value)=>{
console.log("注册在finalRegisty的对象,某一个被销毁,value")/})
let obj1 ={name:"why"}
let info ={age:18}
finalRegistyr.register(obj1,"obj")
finalRegistyr.register(info,"info")
obj1 =null
info =null
Object.values()和Object.keys()的用法
console.log(Object.keys(obj))//[ 'name', 'age', 'height' ]
console.log(Object.values(obj))//[ 'kobe', 38, 1.88 ]
console.log(Object.values("abc"))//[ 'a', 'b', 'c' ]
console.log(Object.entries(obj))//[ [ 'name', 'kobe' ], [ 'age', 38 ], [ 'height', 1.88 ] ]
console.log(Object.entries(["abc","cba","nba"]))//[ [ '0', 'abc' ], [ '1', 'cba' ], [ '2', 'nba' ] ]
const obj2 =Object.entries(obj)
obj2.forEach(item=>{
console.log(item[0],item[1])
})
//name kobe
//age 38
//height 1.88
Object.fromEntries()的用法
//Object.fromEntries为Object.entries的逆方法
const entries =Object.entries(obj)
console.log(entries)
const newentries =Object.fromEntries(entries)
console.log(newentries)
padStart()和padEnd()的用法
const message ="hello world"
const newmessage =message.padStart(15,"*").padEnd(20,"-")
console.log(newmessage) //****hello world-----
flat()和flatMap()的用法
flat():给数组降维度,默认是1
flatMap()的用法:转化为Map类型并降维度
const nums =[10,20,[2,5],[[30,59],[28,39],49,[49,439]]]
const newnums=nums.flat()
console.log(newnums)//[ 10, 20, 2, 5, [ 30, 59 ], [ 28, 39 ], 49, [ 49, 439 ] ]
const newnums1=nums.flat(2)
console.log(newnums1) //[
// 10, 20, 2, 5, 30,
// 59, 28, 39, 49, 49,
//439
]
const message1 =["hello world","hello dog","hello cat"]
const word =message1.flatMap(item=>{
return item.split(" ")
})
console.log(word)//[ 'hello', 'world', 'hello', 'dog', 'hello', 'cat' ]