当前位置:网站首页>Object. fromEntries()
Object. fromEntries()
2022-07-01 16:58:00 【Front end students】
Introduce
Method Object.fromEntries() Convert the list of key value pairs into an object , This method is similar to Object.entries() Relative .
Object.fromEntries([
['foo', 1],
['bar', 2]
])
// {foo: 1, bar: 2}
1、Object Conversion operation
const obj = {
name: 'jimmy',
age: 18
}
const entries = Object.entries(obj)
console.log(entries)
// [Array(2), Array(2)]
// ES10
const fromEntries = Object.fromEntries(entries)
console.log(fromEntries)
// {name: "jimmy", age: 18}
2、Map turn Object
const map = new Map()
map.set('name', 'jimmy')
map.set('age', 18)
console.log(map) // {'name' => 'jimmy', 'age' => 18}
const obj = Object.fromEntries(map)
console.log(obj)
// {name: "jimmy", age: 18}
3、 Filter
course Indicates all courses , Want to request a course score greater than 80 The object of the course :
const course = {
math: 80,
english: 85,
chinese: 90
}
const res = Object.entries(course).filter(([key, val]) => val > 80)
console.log(res) // [ [ 'english', 85 ], [ 'chinese', 90 ] ]
console.log(Object.fromEntries(res)) // { english: 85, chinese: 90 }
4、url Of search Parameter conversion
// let url = "https://www.baidu.com?name=jimmy&age=18&height=1.88"
// queryString by window.location.search
const queryString = "?name=jimmy&age=18&height=1.88";
const queryParams = new URLSearchParams(queryString);
const paramObj = Object.fromEntries(queryParams);
console.log(paramObj); // { name: 'jimmy', age: '18', height: '1.88' }
边栏推荐
- Redis6.0 new features
- 判断一棵二叉树是否为平衡二叉树
- sql刷题586. 订单最多的客户
- Iommu/smmuv3 code analysis (10) page table operation
- Shenyu gateway development: enable and run locally
- Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
- Redis distributed lock
- 剑指 Offer II 105. 岛屿的最大面积
- Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
- 走进微信小程序
猜你喜欢

巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...

【Try to Hack】vulnhub DC4

SQL question brushing 584 Looking for user references

Jojogan practice

C語言輸入/輸出流和文件操作

SQL question brushing 586 Customers with the most orders

【直播预约】数据库OBCP认证全面升级公开课

SQL question brushing 627 Change gender

Template Engine Velocity Foundation

Kali install Nessus
随机推荐
在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
SystemVerilog-结构体(二)
【C补充】【字符串】按日期排序显示一个月的日程
Jojogan practice
如何写出好代码 — 防御式编程指南
sql刷题1050. 合作过至少三次的演员和导演
Today, at 14:00, 15 ICLR speakers from Hong Kong University, Beihang, Yale, Tsinghua University, Canada, etc. continue!
中国PBAT树脂市场预测及战略研究报告(2022版)
How to cancel automatic search and install device drivers for laptops
挖财学堂班主任给的证券账户安全吗?能开户吗?
存在安全隐患 起亚召回部分K3新能源
China BMS battery management system Market Research Report (2022 Edition)
Judge whether the binary tree is a binary search tree
mysql -- explain性能优化
How to solve the keyboard key failure of notebook computer
[live broadcast appointment] database obcp certification comprehensive upgrade open class
Sword finger offer II 015 All modifiers in the string
判断一棵二叉树是否为平衡二叉树
C language input / output stream and file operation
C语言输入/输出流和文件操作