I trying to creating an object from an array that contains many arrays. The array element are to be nested keys of object for each other, only if the key has not be created initially. That is, it should not overwrite key and should also maintained key index.
Example is this -
const MainArray = [
{
key: ['name', 'dog', 'feature', 'hairy'],
value1:1 ,
value2:2
},
{
key: ['name', 'dog', 'eye', 'brown'],
value1:1 ,
value2:2
},
{
key: ['kind', 'human', 'class', 'man', 'height', 'tall'],
value1:'Mike' ,
value2:'John'
},
{
key: ['kind', 'human', 'class', 'woman', 'hobby'],
value1:'Cyling' ,
value2:'Tennis'
},
]
const requiredObject =
{
name:{
dog :{
feature:{
hairy :{value1:1, value2:2}
},
eye:{
brown:{value1:1, value2:2}
}
}
},
kind:{
human:{
class:{
man:{
height:{
tall:{value1:'Mike', value2:'John'}
}
},
woman:{
hobby:{value1:'Cyling', value2: 'Tennis'}
}
}
}
}
}
How can I go from MainArray to requireObject