fix(dedup-array): Object.fromEntries() to convert array to object

This commit is contained in:
Ming Di Leom 2021-06-06 07:51:33 +00:00
parent 413a07b646
commit ad4b53a5c3
No known key found for this signature in database
GPG Key ID: 32D3E28E96A695E8
1 changed files with 4 additions and 4 deletions

View File

@ -74,10 +74,10 @@ input.map(({ name, item }) => [name, item])
input.map((element) => [element.name, element.item]) input.map((element) => [element.name, element.item])
``` ```
Then we pass `stepOne` to `Object.entries`: Then we pass `stepOne` to `Object.fromEntries`:
``` js ``` js
const stepTwo = Object.entries(stepOne) const stepTwo = Object.fromEntries(stepOne)
console.log(stepTwo) console.log(stepTwo)
{ {
@ -90,7 +90,7 @@ console.log(stepTwo)
} }
``` ```
Now we have a de-duplicated object. Then, we use `Object.entries()` to convert it to an array: Now we have a de-duplicated object. Then, we use `Object.entries()` to convert it back to an array:
``` js ``` js
const stepThree = Object.entries(stepTwo) const stepThree = Object.entries(stepTwo)
@ -106,7 +106,7 @@ console.log(stepThree)
] ]
``` ```
Finally, we loop through each element to convert it back to object: Finally, we loop through each element to convert it back to an array of objects:
``` js ``` js
const stepFour = stepThree.map(([name, item]) => { const stepFour = stepThree.map(([name, item]) => {