Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

How can I turn an array object into an object?

I want to put an array object called hello into a constant called answer. At this time, I want to change the key value of the answer to the value key of hello and the value of the answer to the label value of hello.

how can i do that? i was thinking object entries but i couldn't do that.... is it possible??

this is my code

const hello = [
{ label: 'one', value: 'Tangerinefeed' },
{ label: 'two', value: 'dryexamfeed' },
{ label: 'three', value: 'wetfeed' },
{ label: 'forth', value: 'sawdust' },
{ label: 'five', value: 'etc' },
] ;

expected answer

const answer = {Tangerinefeed: 'one', dryexamfeed: 'two', wetfeed: 'three', sawdust: 'forth', etc: 'five'}

Answer*

Draft saved
Draft discarded
Cancel
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center. Commented Jun 21, 2022 at 6:17

lang-js

AltStyle によって変換されたページ (->オリジナル) /