mirror of
https://github.com/alrayyes/wiki.git
synced 2024-12-01 15:26:23 +00:00
29 lines
580 B
Markdown
29 lines
580 B
Markdown
---
|
|
id: 55435d35-26e1-460b-a683-ef346c9972a8
|
|
title: Object.entries
|
|
---
|
|
|
|
# Description
|
|
|
|
Returns [object](20200826201605-objects) properties as key / value
|
|
pairs. Can be used with [maps](20201012093745-javascript_maps) as well.
|
|
It does the opposite of
|
|
[Object.fromEntries](20201116095124-object_fromentries).
|
|
|
|
# Syntax
|
|
|
|
``` javascript
|
|
console.log(Object.entries({ one: 1, two: 2 })); // [['one', 1], ['two', 2]]
|
|
```
|
|
|
|
## Maps
|
|
|
|
``` javascript
|
|
let map = new Map(
|
|
Object.entries({
|
|
one: 1,
|
|
two: 2,
|
|
})
|
|
);
|
|
console.log(JSON.stringify([...map])); // [["one", 1], ["two", 2]]
|
|
```
|