temp = temp[array[i]] = {name:value};
In the above snippet the name is actually a parameter to my function having a value first_name.
Here's the function.
function createHierarchy(obj, group, name, value){
console.log("group = "+group+"\nname ="+name)
var array = group.split(".");
var temp = obj;
var len = array.length;
for(var i = 0; i < len; i++) {
if(temp[array[i]] === undefined)
temp = temp[array[i]] = {name:value};
else
temp = temp[array[i]][name] = value;
}
return obj;
}
The object being dumped has the key name equal to the identifier passed not its dynamic value which was "first_name" .
What am i missing. Let me know if i should update something.
Actual output
name: "cafebabe"
Expected output
first_name : "cafebabe"
FYI
Call this function like
createHierarchy({}, 'personal_details', 'first_name', 'cafebabe')