[
[div]restored: 68
[div2]restored: 88,
[mode]Easy [div]restored: 88
[mode]Normal [div]restored: 99
]
{
div: { restored: 68 },
div2: { restored: 88 },
mode: {
easy: { div: { restored: 88 } },
normal: { div: { restored: 99 } }
}
}
var list = {
'[div]restored': 68,
'[div2]restored': 88,
'[mode]Easy [div]restored': 88,
'[mode]Normal [div]restored': 99
};
Object.entries(list).reduce((acc, [key, value]) => {
const keys = key
.split(/\[(.+?)\]/)
.map(k => k.trim().toLowerCase())
.filter(Boolean)
const last = keys.pop();
keys.reduce(
(sub, key) => sub[key] ?? (sub[key] = {}),
acc
)[last] = value;
return acc;
}, {});