Streamlining an array of dictionaries into a simpler form is the goal.
data = [{A:1},{B:2},{C:3}]
data = {A: 1, B: 2}
data = ["0":{ A : 1, B : 2 , C : 3}]
These two datasets are distinct. Aligning them to a unified format like below is the aim. The initial structure needs to be transformed as shown:
data = [
{
name: "A",
y: 1
},
{
name: "B",
y: 2
},
{
name: "C",
y: 3
}
];
An attempt was made with the following approach, however it proved unsuccessful.
name = {}
data.forEach(function(k,x){
return name['name'] = k , name["y"] = x
})
Your suggestions for a more effective approach are welcome.