Is there a way to transform JSON data like this in JavaScript?
data = [{acquired: "2018-03-09T22:49:52.935Z", mean_ndvi: -0.0483685}
{acquired: "2018-02-13T22:49:16.568Z", mean_ndvi: 0.00595065}
{acquired: "2018-04-01T22:50:30.912Z", mean_ndvi: -0.033455}]
into this precise format?
data = {"2018-03-09T22:49:52.935Z":-0.0483685, "2018-02-13T22:49:16.568Z": 0.00595065, "2018-04-01T22:50:30.912Z": -0.033455}
This is what I've tried so far:
var json =data; var obj2 ={}; var obj3 =[];
for(var i = 0; i < json.length; i++)
{ var obj = json[i];
obj2 = {[obj.acquired]:obj.mean_ndvi};
obj3.push(obj2); }
console.log(obj3);
I am currently getting the output in separate lines like this:
{2018-04-01T22:50:30.912Z: -0.033455},
{2018-04-01T22:50:30.912Z: -0.033455},
{2018-04-01T22:50:30.912Z: -0.033455}
Any suggestions on how to modify it to display the result in one row?