I have an array of string, I want to convert to nested object where key is value of array. I've try with reduce, but all of the value nested with the last object is last item from the array. Can you help me? Thanks!
let m = [
'1.',
'1.1.',
'1.2.',
'1.3.',
'1.4.',
'1.1.1.',
'1.1.2.',
'1.1.3.',
'1.2.1.',
'1.2.2.',
'1.3.1.',
'1.3.2.',
'1.3.3.',
'1.3.4.',
'1.4.1.',
'1.4.3.',
];
I want to convert this array to nested object.
Return
{
"1":{
"1":{
"1":"1.1.1.",
"2":"1.1.2.",
"3":"1.1.3."
},
"2":{
"1":"1.2.1.",
"2":"1.2.2."
},
"3":{
"1":"1.3.1.",
"2":"1.3.2.",
"4":"1.3.4."
},
"4":{
"1":"1.4.1.",
"3":"1.4.3."
}
}
}