-1

Just an easy question, I have this code:

$("#renderBtn").click(
    function () {
        var data =  {"first":[20000, 14000, 12000, 15000, 18000, 19000, 22000], "second":[12000, 11000, 18000, 12000, 19000, 14000, 26000]}
        labels =  ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
            for ( x in data) {
                console.log(x);
                console.log(data.x);
                console.log(data.first);
            }
        }
);

as a result x is array key names which are "first" and "second", I can get values by calling data.first but the return out of data.x is undefined , how I can get values by calling data from x ???

ggorlen
  • 44,755
  • 7
  • 76
  • 106
Soheil
  • 1

1 Answers1

0

You have to use two for loops one for data.first and another data.second beacuse your data is an object. for loop is used to loop through arrays. for ( const x in data.first){console.log(data.first[x]);} You shoud get the values

Rifat
  • 27
  • 1
  • 4