context = keys.reduce((m,v) => { return v in m ? m[v] : m[v] = {}; }, context); context[property] = object[key]; } return result; } alert(JSON.stringify(expand(obj2), null, "\t"));