What's wrong with my code below? grandParent
is undefined, what I want to achieve is each grandparent have a property of parent, and each parent have child (arrays of object too)
like so
[{
name: 'a',
parent: [{
name: 'b',
child: [{
name: 'c'
}]
}]
}]
below code doesn't work
let grandParent = []
_.times(5, () => grandParent.push({
name: faker.name.findName(),
parent: []
}))
grandParent = grandParent.forEach(function(o) {
return o.parent.push({ name: faker.name.findName() })
})
console.log(grandParent) //why here is undefined?