当前位置:网站首页>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' }
边栏推荐
- Detailed explanation of activity life cycle and startup mode
- China nylon 11 industry research and future forecast report (2022 Edition)
- [flask introduction series] cookies and session
- 可迭代对象与迭代器、生成器的区别与联系
- P2893 [USACO08FEB] Making the Grade G(dp&优先队列)
- Building blocks for domestic databases, stonedb integrated real-time HTAP database is officially open source!
- 判断二叉树是否为二叉搜索树
- sql刷题627. 变更性别
- Please, stop painting star! This has nothing to do with patriotism!
- Research and investment strategy report of neutral protease industry in China (2022 Edition)
猜你喜欢

Rhcsa Road

What is the effect of choosing game shield safely in the game industry?

美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告

Girls who want to do software testing look here

Stegano in the world of attack and defense

如何写出好代码 — 防御式编程指南

Iommu/smmuv3 code analysis (10) page table operation

Redis6.0 新功能

sql刷题1050. 合作过至少三次的演员和导演

Leetcode records - sort -215, 347, 451, 75
随机推荐
你还在用收费的文档管理工具?我这有更牛逼的选择!完全免费
String类
Research and investment strategy report of China's sodium sulfate industry (2022 Edition)
How to cancel automatic search and install device drivers for laptops
阿里云、追一科技抢滩对话式AI
Leetcode 216 combined summation III -- backtracking method
How to solve the problem that the battery icon of notebook computer does not display
嗨 FUN 一夏,与 StarRocks 一起玩转 SQL Planner!
SQL question brushing 627 Change gender
sql刷题584. 寻找用户推荐人
Redis 分布式锁
Detailed explanation of activity life cycle and startup mode
Rhcsa Road
SystemVerilog-结构体(二)
Bugku's file contains
Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
[jetsonnano] [tutorial] [introductory series] [III] build tensorflow environment
Rhcsa Road
Kali install Nessus
美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告