当前位置:网站首页>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' }
边栏推荐
- ACL 2022 | 分解的元学习小样本命名实体识别
- 如何写出好代码 — 防御式编程指南
- Soft test network engineer full truth simulation question (including answer and analysis)
- 挖财学堂班主任给的证券账户安全吗?能开户吗?
- Template Engine Velocity Foundation
- Sword finger offer II 015 All modifiers in the string
- 模板引擎Velocity 基礎
- Judge whether a binary tree is a balanced binary tree
- 【直播预约】数据库OBCP认证全面升级公开课
- [C language supplement] judge which day tomorrow is (tomorrow's date)
猜你喜欢
美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
Redis6.0 new features
How to repair the laptop that cannot connect to the wireless network
What is the effect of choosing game shield safely in the game industry?
Hi Fun Summer, play SQL planner with starrocks!
How to use etcd to realize distributed /etc directory
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
【C补充】【字符串】按日期排序显示一个月的日程
[live broadcast appointment] database obcp certification comprehensive upgrade open class
在MeterSphere接口测试中如何使用JMeter函数和MockJS函数
随机推荐
How to repair the laptop that cannot connect to the wireless network
存在安全隐患 起亚召回部分K3新能源
AI高考志愿填报:大厂神仙打架,考生付费围观
How to restore the system of Sony laptop
Babbitt | yuan universe daily must read: Naixue coin, Yuan universe paradise, virtual stock game Do you understand Naixue's tea's marketing campaign of "operation pull full"
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
Introduction to software engineering - Chapter 6 - detailed design
sql刷题1050. 合作过至少三次的演员和导演
Cookies and session keeping technology
Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
String类
MySQL learning summary
Soft test network engineer full truth simulation question (including answer and analysis)
机器学习11-聚类,孤立点判别
【Kotlin】高阶函数介绍
美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
游戏行业安全选择游戏盾,效果怎么样?
Are you still using charged document management tools? I have a better choice! Completely free
Sword finger offer II 015 All modifiers in the string
Basic use of MySQL