当前位置:网站首页>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' }
边栏推荐
- How to repair the laptop that cannot connect to the wireless network
- Chinese diosgenin market forecast and investment strategy report (2022 Edition)
- Installation and use of sqoop
- 英特尔开源深度学习工具库 OpenVINO,将加大与本土软硬件方合作,持续开放
- 阿里云、追一科技抢滩对话式AI
- SystemVerilog-结构体(二)
- 多线程并发之CountDownLatch阻塞等待
- [wrung Ba wrung Ba is 20] [essay] why should I learn this in college?
- sql刷题586. 订单最多的客户
- Leetcode 216 combined summation III -- backtracking method
猜你喜欢
可迭代对象与迭代器、生成器的区别与联系
智能运维实战:银行业务流程及单笔交易追踪
如何使用 etcd 实现分布式 /etc 目录
博睿数据一体化智能可观测平台入选中国信通院2022年“云原生产品名录”
Pytest learning notes (13) -allure of allure Description () and @allure title()
Buuctf gold III
重磅披露!上百个重要信息系统被入侵,主机成为重点攻击目标
ShenYu 网关开发:在本地启用运行
How to use etcd to realize distributed /etc directory
GameFramework食用指南
随机推荐
AI college entrance examination volunteer filling: the gods of Dachang fight, and candidates pay to watch
Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022
为什么你要考虑使用Prisma
Dataframe gets the number of words in the string
想做软件测试的女孩子看这里
How to restore the system of Sony laptop
Basic use of MySQL
Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!
sql刷题1050. 合作过至少三次的演员和导演
Leetcode 216 combined summation III -- backtracking method
字节跳动数据平台技术揭秘:基于 ClickHouse 的复杂查询实现与优化
拼接字符串,得到字典序最小的结果
Exclusive news: Alibaba cloud quietly launched RPA cloud computer and has opened cooperation with many RPA manufacturers
P2893 [USACO08FEB] Making the Grade G(dp&优先队列)
越来越多地使用 SLO 来实现可观测性|DevOps
Detailed explanation of activity life cycle and startup mode
Installation and use of sqoop
Template engine velocity Foundation
《中国智慧环保产业发展监测与投资前景研究报告(2022版)》
游戏行业安全选择游戏盾,效果怎么样?