After organizing my data, I am looking to convert it into a flat structure
data = [
{
"Name":"Gorba Technology",
"Product":"Dell",
"City":[
"Delhi",
"Mumbai"
]
},
{
"Name":"Suvidha Computer",
"Product":"Lenovo",
"City":[
"Deoghar"
]
},
{
"Name":"Sara Laptop",
"Product":"Dell",
"City":[
"Noida",
"Delhi"
]
}
]
The desired output should look like this:
[{"Name":"Gorba Technology","City":"Delhi"},
{"Name":"Gorba Technology","City":"Mumbai"},
{"Name":"Suvidha Computer","City":"Deoghar"},
{"Name":"Sara Laptop","City":"Rajasthan"}
{"Name":"Sara Laptop","City":"Delhi"}]
I attempted the following approach but was unsuccessful:
var result = data.map(({Name, City}) => City.map(item => {Name, item}));
In an attempt to achieve the desired output without using flatMap
,
I encountered lint errors when trying to implement flatMap
.