当前位置:网站首页>Object.entries()
Object.entries()
2022-08-02 12:34:00 【m0_67394006】
Object.entries() method returns an array of key-value pairs for the given object's own enumerable properties.
The order is the same as that returned when looping over the object using for...in (the difference being that the for-in loop also enumerates properties in the prototype chain).
Syntax
Object.entries(obj)
Parameters
obj: An object that can return key-value pairs of its enumerable properties.
Return value
An array of key-value pairs for the given object's own enumerable properties.
Description
Object.entries() returns an array whose elements are the arrays corresponding to the key-value pairs of enumerable properties found directly on object.The properties are in the same order as given by manually looping through the object's property values.
The parameter is an object
const obj = { name: 'xiaoming', age: 'seven',sex: 'man', grade: 'four' };const res = Object.entries(obj)console.log(res);Run result:

The parameter is an array
const obj = [1,2,3,4,5,6]const res = Object.entries(obj)console.log(res);Run result:

The parameter is an array (the array contains objects)
const obj = [1,2,3,4,5,6,{a:'a'},{b:'b'},{c:'c'}]const res = Object.entries(obj)console.log(res);Run result:
The parameter is an array (the elements in the array are objects)
const obj = [{a:'a'},{b:'b'},{c:'c'}]const res = Object.entries(obj)console.log(res);Run result:
Objectconverted to Map
The
new Map()constructor accepts an iterable ofentries.With the help of theObject.entriesmethod you can easily convertObjecttoMap.
const obj = { name: 'xiaoming', age: 'seven',sex: 'man', grade: 'four' };console.log(Object.entries(obj));const map = new Map(Object.entries(obj));console.log(map);Run result:

Summary
Object.entries() can traverse the key value of an object in the form of an array. The result is the same as the result returned when for...in loops through the object, but it will not traverseits prototype properties.
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
猜你喜欢

Openlayers Quick Start Tutorial

Js scratchable latex style draw plug-in
![#Summer Challenge#[FFH] OpenHarmony Device Development Foundation (3) Compilation Dependencies](/img/bd/22b83e1118a4522f8cb6523fd16043.png)
#Summer Challenge#[FFH] OpenHarmony Device Development Foundation (3) Compilation Dependencies

Data Lake (3): Hudi Concept Terminology

php——三篇夯实根基第一篇

Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。

JVM学习----垃圾回收调优

After Effects 教程,如何在 After Effects 中对蒙版进行动画绘制?

FreeRTOS实验--一个函数创建多个任务

三种实现分布式锁的方式
随机推荐
LeetCode_377_Combination Sum IV
Interpretation of new features | MySQL 8.0 GIPK invisible primary key
看我如何用多线程,帮助运营小姐姐解决数据校对系统变慢!
js stopwatch countdown plugin
Free Chinese-English Translation Software - Automatic Batch Chinese-English Translation Software Recommended Daquan
Js scratchable latex style draw plug-in
js源码跳转的几种方式,在当前页面跳转,在空白页跳转
Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单。
Software component analysis: 5 major capabilities to protect software supply chain security
SQL Server 2019安装错误0x80004005 服务没有及时响应启动或控制请求详细解决方法
设置代理服务器(谷歌+IE)「建议收藏」
To eliminate air bubbles to save the mushroom h5 small game source code
pytorch model to tensorflow model
SQL Server2019安装步骤及脱机安装Microsoft机器学习组件下一步不能继续的问题
unique in numpy & pandas
pytorch模型转tensorflow模型
FreeRTOS--stack experiment
numpy&pands 中的unique
Drools(8):WorkBench使用
SQL Server database generation and execution of SQL scripts