I want to get all the keys in an array of objects. Initially, I just grabbed the first object in the array and used:
var keys = Object.keys(tableData[0]);
But when I looked closer to the data, I noticed that the first line does not contain all the necessary keys. In the following example, the third element contains all the keys, but you may have a case where getting all the keys requires combining several objects.
var tableData = [ { first:"jeff", last:"doe", phone: "2891" }, { first:"sarah", phone:"this", county: "usa" } { first:"bob", last:"brown", county: "usa", phone: "23211" } ];
How can I get all the unique keys in an array of objects that will be efficient on a large scale?
json javascript sorting arrays
Philip kirkbride
source share