I need to extract only the names of the objects (cat, dog, bird)
/// Names of objects I want to retrieve ///
var storage = [
{cat: {name: "Garfield", count: 3443, price: 1000}},
{bird: {name: "Eagle", count: 4042, price: 3000}},
{dog: {name: "Rex", count: 1488, price: 2000}}
];
function extractObjectNames(storage) {
var keys = [];
for(var key in storage) {
keys.push(key);
if(typeof storage[key] === "object") {
var subkeys = extractObjectNames(storage[key]);
keys = keys.concat(subkeys.map(function(subkey) {
return key + "." + subkey;
}));
}
}
console.log(keys);
return keys;
}
extractObjectNames(storage);