-3

I have JSON data as follows,

var data={'08/06/2020': Array(1), '08/07/2020': Array(1), '08/08/2020': Array(1), '08/09/2020': Array(1), '08/10/2020': Array(1), …}

Trying to loop through the object keys, but getting an undefined error,

data.keys(function(v,i){ 
   // some code
 });
sridharnetha
  • 2,104
  • 8
  • 35
  • 69
  • Have you tried `Object.keys` instead of `keys`? – jmargolisvt Sep 06 '20 at 17:25
  • It's because [`Object#keys`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys) is a method that only exists in the [`Object` built-in object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object). – Edric Sep 06 '20 at 17:25

1 Answers1

2

Using Object.keys and delete the ,... at the end of your object.

var data={'08/06/2020': Array(1), '08/07/2020': Array(1), '08/08/2020': Array(1), '08/09/2020': Array(1), '08/10/2020': Array(1)}

Object.keys(data).forEach(key => console.log(key));
Sascha
  • 4,576
  • 3
  • 13
  • 34