JSFiddle - React, Tailwind, and code Playground
by caio
JavaScript
function createAssociativeArray(string, object) {
string = string.split('.');
return string.reduce(function(_object, _target, i) {
_object[_target] = (i + 1 === string.length ? object : {});
return _object;
});
}
var response = createAssociativeArray('key1.key2.key3', {
data1: 1,
data2: 2,
data3: 3
});
console.log(response);
document.body.innerText = 'See your console. :)';