I'm struggling to work out how I can push my array keys to an array of its own which I'm eventually going to use as column headings.
The below successfully logs my keys however the push is breaking
let cols = []
data.forEach(function (obj, index) {
if (index === 0)
{
console.log(Object.keys(obj));
this.cols.push(Object.keys(obj));
}
});
I don't actually have to loop the whole data object either I only need the first index but 1 step at a time!
My end result I expect would be cols = ["ValueDate", "AccountName", "Holding"]
Any thoughts please
Thnaks GWS
Data Extract:
[
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHAUD",
"Holding": 318622.53
},
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHCAD",
"Holding": 7195
},
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHEUR",
"Holding": 5077.97
},
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHGBP",
"Holding": 19625
},
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHJPY",
"Holding": 16463
},
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHNZD",
"Holding": 601.56
},
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHSGD",
"Holding": 1000
},
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHUSD",
"Holding": 1716906.25
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHAUD",
"Holding": 318622.53
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHCAD",
"Holding": 7195
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHEUR",
"Holding": 5077.97
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHGBP",
"Holding": 19625
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHJPY",
"Holding": 16463
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHNZD",
"Holding": 601.56
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHSGD",
"Holding": 1000
},
{
"ValueDate": "2017-04-27T14:16:00",
"AccountName": "CASHUSD",
"Holding": 1720781.25
}
]