JSFiddle - React, Tailwind, and code Playground
JavaScript
var doc = {
title: 'a title',
date: 'a date',
send: {
date: new Date(),
sender: 'a sender',
receiver: 'a receiver',
thing: {
fullname: {
first: 'Bob',
last: 'Smith'
}
}
}
}
function findDeepProp(obj, prop) {
var target = prop.split('.'),
out;
(function iterate(obj, target) {
var tmp = target.shift();
if (target.length === 0 && obj[tmp]) return out = obj[tmp];
if (obj[tmp] && typeof obj[tmp] === 'object') iterate(obj[tmp], target);
return;
}(obj, target));
return out;
}
console.log(findDeepProp(doc, 'send.thing.fullname.first'))
console.log(findDeepProp(doc, 'send.thing.fullname.last'))