0
Hi how to access to the siblings array, or how to display the routes in the console or UI?
let array = [ {name: 'John', path: '/one/two/'}, {name: 'Gabi', path: '/three/four/'}, {name: 'Dan', path: '/five/six/', routes: [{name: 'Stefan', path: '/ten/eleven/'}]} ]; Or how can i loop through that?
2 Antworten
+ 3
array.forEach( obj=> if (obj.routes) console.log(obj.routes))
+ 3
var routes = array.filter( obj=> obj.routes).map(r=>r.routes.filter(a=>a.path)).flat();
https://code.sololearn.com/Wfl6H7UzQW03/?ref=app