I have object:
const data3 = [
{
calculatedPropertyDescription: "where evri_courionsignature_gb is Dispatched",
category: "red",
tags: [
{ name: 'LandingPage', value: 'true' },
{ name: 'Country', value: 'GB' },
{ name: 'Carrier', value: 'RoyalMail' },
{ name: 'EventCode', value: 'Dispatched' },
]
},
{
calculatedPropertyDescription: "where evgnature_gb is Dispatched",
category: "red",
tags: [
{ name: 'LandingPage', value: 'true' },
{ name: 'Country', value: 'USA' },
{ name: 'Carrier', value: 'Evri' },
{ name: 'EventCode', value: 'Dispatched' },
]
},
]
I need from tags: create array of pairs values.
For exmple from:
{ name: 'LandingPage', value: 'true' },
I need get:
[..., 'LandingPage:true', 'Country:GB',...]
Thank you
3
Answers
A simple
Array#map()
will do:Explanation: This means "convert each tag object in a list of tags to a string which is concatenated from the tag’s
name
, a colon andvalue
"..map()
means to do something for every element in a given array.Try it:
I will try to assume that there should be one array at the output:
If you need to separate results:
Assumming that you want everything on the
tags
in that format, in one array then you can do it like this with forEach