0

I have an object like this:

{
   "2020-02-16 00:00:00":2973174.0,
   "2020-02-17 00:00:00":2972752.0
}

I want to create a chart to display time and value. How can i loop through this object as if it was an array?

malifa
  • 8,025
  • 2
  • 42
  • 57

1 Answers1

0

Use Object.entries method that returns an array of a given object in [key, value] pairs

Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries

var obj= {"2020-02-16 00:00:00":2973174.0,"2020-02-17 00:00:00":2972752.0,"2020-02-18 00:00:00":2972498.0,"2020-02-19 00:00:00":2972105.0,"2020-02-20 00:00:00":2972685.0,"2020-02-21 00:00:00":2973405.0,"2020-02-22 00:00:00":2973616.0,"2020-02-23 00:00:00":2973583.0,"2020-02-24 00:00:00":2973217.0,"2020-02-25 00:00:00":2973748.0,"2020-02-26 00:00:00":2974198.0,"2020-02-27 00:00:00":2976647.0,"2020-02-28 00:00:00":2977413.0,"2020-02-29 00:00:00":2977437.0,"2020-03-01 00:00:00":2977735.0,"2020-03-02 00:00:00":2977724.0,"2020-03-03 00:00:00":2977444.0,"2020-03-04 00:00:00":2977115.0,"2020-03-05 00:00:00":2977001.0,"2020-03-06 00:00:00":2976990.0,"2020-03-07 00:00:00":2976907.0,"2020-03-08 00:00:00":2979136.0,"2020-03-09 00:00:00":2980402.0,"2020-03-10 00:00:00":2980920.0,"2020-03-11 00:00:00":2980963.0,"2020-03-12 00:00:00":2981170.0,"2020-03-13 00:00:00":2981574.0,"2020-03-14 00:00:00":2981742.0,"2020-03-15 00:00:00":2983570.0,"2020-03-16 00:00:00":2984018.0}

console.log(Object.entries(obj));
joy08
  • 9,004
  • 8
  • 38
  • 73