If I have:
name.sub = function() {
    var sub = {};
    var placeholder = "test"
    var test = function() {
        return 42;
    };
    // Desired code would be here
    return sub;
};
I want to use a placeholder to access the variable so that I get 42.
Something like 
window["name"]["sub"][placeholder] is seemingly looking for name.sub.test.
The only answers I found were if it was a global variable. Using eval would work, but I've heard it should be avoided where possible.
placeholder = "test"; 
console.log(eval(placeholder + '()'))
// Would return 42
My actual end goal is to have an associative array where:
console.log(array[placeholder]);
// Would return 42
Any help would be appreciated.
This is what I ended up using for anyone interested:
name.sub= function() {
    var sub = {};
    var placeholder = "test"
    var test = function() {
        return 42;
    var newObj = {};
    newObj["test"] = function() {test()}
    console.log(newObj[placeholder]())
    // Should return 42
    };




window["name"]["sub"][window["name"]["sub"]["placeholder"]]()?name.sub.input(variable)whereinputwould convertvariableto a string (e.g."test"). I want to find out what the variabletestis equal to. Hope that cleared it up a bit. Though I think it'll be rabbit hole of why I want to do that.