I want to pull specific parts (definitely not all) from this object:
var metadata = {
cat: {
id: 'id',
name: 'kitty',
},
dog: {
id: 'id',
name: 'spot',
owner: {
name: 'ralph',
}
}
//tons of other stuff
};
I would like to do something like this:
var fields = ['cat.id', 'dog.name', 'dog.owner.name'];
fields.forEach( function(key) {
console.log(metadata[key]); //obv doesn't work
});
This is a simplified scenario where I'm trying to validate specific fields in metadata. Is there a straightforward way to do this?