I am generating a JavaScript object based on a CSV file that I have.
Here is what the object currently looks like-- an array of objects:
[
{
"country": "afghanistan",
"iso3": "afg",
"first_characteristic": 3,
"second_characteristic": 5,
"third_characteristic": 3
},
{
"country": "united states",
"iso3": "usa",
"first_characteristic": 8,
"second_characteristic": 6,
"third_characteristic": 7
},
{
"country": "china",
"iso3": "chn",
"first_characteristic": 6,
"second_characteristic": 0.7,
"third_characteristic": 2
}
]
I'd like to add a name to each object, that is derived from one of its values, and for the output to be a nested object.
So this is what I want the new object to look like:
{
"afg":{
"country": "afghanistan",
"iso3": "afg",
"first_indicator": 3,
"second_indicator": 5,
"third_indicator": 3
},
"usa":{
"country": "united states",
"iso3": "usa",
"first_indicator": 8,
"second_indicator": 6,
"third_indicator": 7
},
"chn":{
"country": "china",
"iso3": "chn",
"first_indicator": 6,
"second_indicator": 0.7,
"third_indicator": 2
}
}
I can't figure out how to add these names. Any help is greatly appreciated.
[foo: bar, fizz: buzz]is not a valid Array in JavaScript. Are you saying you want both indices and keys? just keys? just indicies but labels somehow attached?"...": {...}. Is there any need for it to be an array, could it be an object?