JSFiddle - React, Tailwind, and code Playground

by jbabey

JavaScript

var getPropertyByName = function (fullString, context) {
        var namespaces = fullString.split(".");
        var functionName = namespaces.pop();
        
        for (var i = 0; i < namespaces.length; i++) {
            context = context[namespaces[i]];
        }
        
        return context[functionName];
};

window.MyCustomObject = {};
window.MyCustomObject.foo = {
    bar: 'worked'
};

console.log(getPropertyByName('MyCustomObject.foo.bar', window));