当前位置:网站首页>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.entries
method you can easily convertObject
toMap
.
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
边栏推荐
- SQL中字符串拼接
- How to use the database like tap water?|Tencent Cloud Database TDSQL-C
- ssm access database data error
- 手撸架构,Mysql 面试126问
- Manual architecture, Mysql interview 126 questions
- liunx基础命令讲解
- Software component analysis: 5 major capabilities to protect software supply chain security
- SQL Server 数据库之生成与执行 SQL 脚本
- js真3d柱状图插件
- Do you really understand the business process service BPass?
猜你喜欢
7种最常用数据分析思维,解决95%的分析难题
Data Lake (3): Hudi Concept Terminology
php字符串的截取方式
js炫酷仪表盘插件
用位运算为你的程序加速
一款强大的js弹出alert插件
numpy&pands 中的unique
DTG-SSOD: The latest semi-supervised detection framework, Dense Teacher (with paper download)
Import and export data of SQL Server database
Js scratchable latex style draw plug-in
随机推荐
kvm部署
【第六届强网杯CTF-Wp】
SQL Server 2014 installation tutorial (nanny-level graphic tutorial)
PHP+MYSQL【学生信息管理系统】(极简版)
Intelligent Image Analysis-Intelligent Home Appliance Image Target Detection Statistical Counting Detection and Recognition-iCREDIT
以Boost为例的type3电压环补偿器实例
设置代理服务器(谷歌+IE)「建议收藏」
第11章 文件
Do you really understand the business process service BPass?
TFRecord简介,原理分析,代码实现?[通俗易懂]
js炫酷仪表盘插件
用位运算为你的程序加速
内存存储结构
数据湖(三):Hudi概念术语
pytorch模型转tensorflow模型
Technology sharing | Description of the electronic fence function in the integrated dispatching system
数据湖(二):什么是Hudi
如何更好评估信用贷风险?看这场评分卡模型直播就可以了
SQL中字符串拼接
FreeRTOS creation tasks - dynamic creation, static creation