javascript - Split Array of Objects -


is there way of changing array of objects few seperate arrays each property of objects?

for example, have this:

[      {          date: mon aug 08 2016 16:59:16 gmt+0200 (cest),         visits: 0,         hits: 578,         views: 5131      },     {          date: tue aug 09 2016 16:59:16 gmt+0200 (cest),         visits: -1,         hits: 548,         views: 722      },     {          date: wed aug 10 2016 16:59:16 gmt+0200 (cest),         visits: -1,         hits: 571,         views: 4772      } ] 

and want this:

var dates = ["date1", "date2", ...],     visits = ["visit1", "visit2", ...],     hits = ["hits1", "hits2", ...],     views = ["view1", "view2", ...]; 

so can use plot.ly.

you can use map:

var array =  [ { "date": 'mon aug 08 2016 16:59:16 gmt+0200 (cest)',      visits: 0,      hits: 578,      views: 5131 },    { "date": 'tue aug 09 2016 16:59:16 gmt+0200 (cest)',      visits: -1,      hits: 548,      views: 722 },    { "date": 'wed aug 10 2016 16:59:16 gmt+0200 (cest)',      visits: -1,      hits: 571,      views: 4772 }];    var dates = array.map(item => item.date);  var visits = array.map(item => item.visits);  var hits = array.map(item => item.hits);  var views = array.map(item => item.views);    console.log(dates, visits, hits, views);


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -