I had the following object:
var dataset = [
[
{"value":"PRE","formattedValue":"PRE"},
{"value":"2017-06-15 00:00:00","formattedValue":"15/06/2017 0:00:00"},
{"value":"COSTA RICA","formattedValue":"COSTA RICA"},
{"value":"6.15","formattedValue":"6,150"}
],
[
{"value":"PRE","formattedValue":"PRE"},
{"value":"2017-06-15 00:00:00","formattedValue":"15/06/2017 0:00:00"},
{"value":"EL SALVADOR","formattedValue":"EL SALVADOR"}
]
]
Its too complex and has data I don't actually need, so I tried to turn it into this:
[
{
"estado": "PRE",
"fecha": "2017-06-15 00:00:00",
"pais": "COSTA RICA",
"precio": "6.15",
}
]
I finally did it, but I'n unsure why my code works. I done it with this code:
var datafinal = [];
function convertion(){
var dataobj = dataset.getData();
for(var x in dataobj){
datafinal[x] = { "estado": dataobj[x][0]["value"] };
datafinal[x]["fecha"] = dataobj[x][1]["value"];
datafinal[x]["pais"] = dataobj[x][2]["value"];
datafinal[x]["precio"] = dataobj[x][3]["value"];
}
}
If you pay attention, you'll see the first value i add to the new object is using a different format to get added than the rest.
I discovered that if i add every value with the second format it adds nothing. But if i add everything in the first format, it only adds the last value;
So, i made the vale in the first format, and the rest in the second format, and it worked just fine.
...why though, can someone explain to me why is this happening?
dataset, but not whatdataset.getData()returns.