v1
6/14/2021 by matiaslopezd -00
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
Object.byStringFor = function(object, string) {
    string = string.replace(/\[(\w+)]/g, '.$1'); // convert indexes to properties
    string = string.replace(/^\./, ''); // strip a leading dot
    const array = string.split('.');
    for (let index = 0, limit = array.length; index < limit; ++index) {
        const key = array[index];
        if (key in object) {
            object = object[key];
        } else {
            return;
        }
    }
    return object;
}

Object.byStringForeach = function(object, string) {
    string = string.replace(/\[(\w+)]/g, '.$1'); // convert indexes to properties
    string = string.replace(/^\./, ''); // strip a leading dot
    const array = string.split('.');
    array.forEach((key) => {
        if (key in object) object = object[key];
    });
    return object;
}

const object = {
    a: {
        b: {
            c: 1
        }
    }
};
delete caserun single casemove downdrag and drop case


ready



Object.byStringFor(object, 'a.b.c');
delete caserun single casemove updrag and drop case


ready



Object.byStringForeach(object, 'a.b.c');
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN