I want to use underscore to go iterate each item and append a period to the end of each fruit's name, and return an array. But there can be many nested levels.
`const` `NESTED =` `[
{name: 'Apple',
items: [{
name: 'Orange',
items: [{name: 'Banana'}]
}]},
{name: 'Pear'}]`
My final should look like this:
`NESTED =` `[{ name: 'Apple.', items: [{name: 'Orange.', items: [{name: 'Banana.'}]}]}, { name: 'Pear.'}]`
There can be many and many items within. This is where I am stuck, my current underscore function only gets the first level, using ._map:
let items = _.map(NESTED, function(item){
return {
// append the period here, but doesn't go deeper
}
});
What is a good way to do this?
This should work for the example data that you supplied.
Should be easy enough to translate the pure JS into underscore.
Update: direct conversion to underscore