ES6-ES12笔记(1)

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' ]

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值