0

This is a function I wrote to iterate through a js object and set the values to an array.

function prepareSalesDataForRedis(previousSalesData) {
let sale_value = [];

for(var key in previousSalesData) {
    let record = {name : key, y : previousSalesData[key], drilldown: previousSalesData[key]}
    sale_value.push(record);
}
return sale_value;
}

But the output is ordered in a different order. enter image description here

Can do this by iterating with simple for loop. But why does the for in retrieves the records in no particular order. The expectation is that, Friday should appear as the first record in the output. Would appreciate some explantation.

Phil
  • 157,677
  • 23
  • 242
  • 245
Nirojan Selvanathan
  • 10,066
  • 5
  • 61
  • 82

0 Answers0