Here is the JSON that I have:
[
"Spain",
"2010",
"Brazil",
"1994",
"Brazil",
"1970",
"Brazil",
"1962",
"Brazil",
"2002",
"Brazil",
"1958",
"Germany",
"2014",
"Germany",
"1990",
"Germany",
"1974",
"Germany",
"1954",
"Italy",
"2006",
"Italy",
"1982",
"Italy",
"1938",
"Italy",
"1934",
"France",
"2018",
"France",
"1998",
"Argentina",
"1986",
"Argentina",
"1978",
"Uruguay",
"1930",
"Uruguay",
"1950",
"England",
"1966"
]
I'm trying to convert it into multiple array objects of key-value pair like below.
{
"name": "Spain",
"year": 2010
},
{
"name": "Brazil",
"year": 1994, 1970, 1962, 2002, 1958
},
...
]
Is there any way to achieve the above structure? I have tried couple of methods using array map function but it doesn't give in the desired output.
const dataMap = Object.keys(s).map((filename) => {
return {
name: filename,
year: s[filename]
}
})
How can it be done in Node.js??
yearproperty be an array?