Given the following array structure:
objNeeded = [
{onelevel: 'first'},
{
onelevel: 'second',
sublevels: [
{onelevel: 'domain'},
{onelevel: 'subdomain'}
]
},
{
onelevel: 'third',
sublevels: [
{
onelevel: 'fourth',
sublevels: [
{onelevel: 'domain'}
]
}
]
}
];
The objective is to transform it into this object structure:
objNeeded = {
first: true,
second: {
domain: true,
subdomain: true
},
third: {
fourth: {
domain: true
}
}
};
This transformation may involve more nested objects and additional items in the original array.
What approach can be used to achieve this using JavaScript or Typescript?