I am facing a challenge in figuring out how to extract and push my array keys into a separate array, which I plan to use as column headings.
The code below successfully logs the keys from my data, but encounters an issue when trying to push them into another array:
let cols = []
data.forEach(function (obj, index) {
if (index === 0)
{
console.log(Object.keys(obj));
this.cols.push(Object.keys(obj));
}
});
I only need to extract the keys from the first object in the data array at the moment. Taking it one step at a time!
The expected end result for 'cols' would be ["ValueDate", "AccountName", "Holding"]
If you have any insights or suggestions, please share!
Thanks a lot! GWS
Data Sample:
[
{
"ValueDate": "2017-04-26T14:16:00",
"AccountName": "CASHAUD",
"Holding": 318622.53
},
...
...
(remaining data elements truncated for brevity)
]