1
I’m making a code here, with the following object:
{
path: 'mtw',
return: 'hi',
obj: {
path: 'he-mele-no-lilo',
return: 'hi',
obj: {
path: 'hawaiian',
return: 'hi',
obj: {
path: 'swiss',
return: 'hi',
obj: {
path: 'altendorf',
return: 'hi',
}
}
}
}
}
and I need to get in each obj and so catch all the "obj", I tried to do this with reduce:
const res = arr.reduce(function(s: any, a: any){
console.log(s);
console.log(a);
return s;
}, {});
but it doesn’t get into all the objects, so as I can do, I’m doing something wrong?
Edit: I look for a result like [{path: 'mtw', Return: 'hi'}, {path: 'he-Mele-no-Lilo', Return: 'hi'}, path: 'Hawaiian', Return: 'hi']
What is the result you are looking for? You can give an example of what
res
should be?– Sergio
res should be:
[{path: 'mtw', return: 'hi'}, {path: 'he-mele-no-lilo', return: 'hi'}, path: 'hawaiian', return: 'hi']
....– mtwzim