I have the following object:
var result = [{
"id": 89304,
"employeeDetails": {
"id": 102524,
"version": 9
}
}];
This is a snippet from a larger object that I'm trying to push into a MySQL table. What I'm trying to achieve is extract just the values into their own array, which would return this:
[ '89304', '102524', '9' ]
This way, I can easily push the values to the DB.
I have tried doing the following which works fine without nesting:
obKeys = Object.keys(result);
console.log(obKeys);
However, with the nesting, the result I am getting is the following:
[ '0' ]
Can anyone let me know where I am going wrong, or suggest an alternative (better) way of doing this?
Thanks.
Object.keys()
on an array instead of an object. 2) If it were an object,Object.keys()
will return you the keys instead of the values. 3) The order of an object's properties is not guaranteed in JavaScript, so neither will be the order of your resulting array.