当前位置:网站首页>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 solve the keyboard key failure of notebook computer
- 荣威 RX5 的「多一点」产品策略
- Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
- 巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
- String class
- Redis distributed lock
- Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
- Tutorial on the principle and application of database system (001) -- MySQL installation and configuration: installation of MySQL software (Windows Environment)
- Flux d'entrées / sorties et opérations de fichiers en langage C
- What are the differences between PHP and DW
猜你喜欢

SQL question brushing 627 Change gender

Redis6.0 new features

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

阿里云、追一科技抢滩对话式AI

Pytest learning notes (13) -allure of allure Description () and @allure title()

换掉UUID,NanoID更快更安全!

【flask入门系列】Cookie与Session

多线程并发之CountDownLatch阻塞等待

如何使用 etcd 实现分布式 /etc 目录

How to use F1 to F12 correctly on laptop keyboard
随机推荐
巴比特 | 元宇宙每日必读:奈雪币、元宇宙乐园、虚拟股票游戏...奈雪的茶这波“操作拉满”的营销活动你看懂了吗?...
【Try to Hack】vulnhub DC4
Basic usage of Frida
Rhcsa Road
Redis6.0 new features
Soft test software designer full truth simulation question (including answer analysis)
Rhcsa Road
Research and investment strategy report of hydroxypropyl beta cyclodextrin industry in China (2022 Edition)
6月刊 | AntDB数据库参与编写《数据库发展研究报告》 亮相信创产业榜单
Redis 分布式锁
[Supplément linguistique c] déterminer quel jour est demain (date de demain)
What is the effect of choosing game shield safely in the game industry?
如何写出好代码 — 防御式编程指南
libcurl下载文件的代码示例
中国乙腈市场预测与战略咨询研究报告(2022版)
Dataframe gets the number of words in the string
How wild are hackers' ways of making money? CTF reverse entry Guide
Machine learning 11 clustering, outlier discrimination
SystemVerilog-结构体(二)
今天14:00 | 港大、北航、耶鲁、清华、加大等15位ICLR一作讲者精彩继续!