I have the following Javascript object:
doc = {};
doc.title = 'a title';
doc.date = 'a date';
doc.send = {
date: new Date(),
sender: 'a sender',
receiver: 'a receiver'
};
And i have the following function:
doSomething(item, property) {
console.log(item[property];
}
It works if i call doSomething(doc, 'date')
, but it doesn't work if i use doSomething(doc, 'send.date')
.
Since that function have to be reusable, how to let it handling any type of property, including nested one?
I see that lodash
could be helpful with _.get
, but i'm using underscore
that not include that method. In addition i prefer not to use and install other libraries. Any idea?