I have an array who look like this:
tab [
0: {
firstName: John,
lastName: Doe,
situation: married,
familyMembers: 5,
}
1: {
firstName: Jack,
lastName: Daniel,
situation: single,
familyMembers: 6,
}
]
I need something like this:
{
[John]: {[Doe]: 5,
[Jack]: {[Daniel]: 6,
}
I tried something like this:
tab.map((item) => {
return (
{[item.firstName]: {[item.lastName]: item.familyMembers}}
)
})
But even without considering that I have an array instead of an object the result look like this:
[
0: {
[John]: {[Doe]: 5,
}
1: {
[Jack]: {[Daniel]: 6,
}
]
Any suggestion here will be appreciate I tried using reduce but as I probably don't use it well it make really bad result.