Skip to content
Advertisement

How to map an array of objects in a a new array with new key value

I have a situation where I have an array of objects like this:

JavaScript

I have to remap the above OBJ to a new one containing its translation which is similar to this from React-intl: formatMessage(formatMessage(messages.emailOptionPlaceholder)

And the idea is as follow:

JavaScript

so the new array should contain the right translation which will populate a dropdown menu.

I tried so far like this but without success:

JavaScript

This gives back 3 arrays instead of one with the values I need.

My goal is to have an array containing the formatMessage(...) output for the 3 elemnts inside the object as example of the output:

JavaScript

I’m getting that OBJ from back-end and need to put the translation of corresponding name inside a drop down menu and was wondering what solution can be better.

Advertisement

Answer

I would do it something like this. (not tested)

JavaScript

If you are only interested in the values you can do this.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement