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?

27th Feb 2020, 9:34 PM
Ahmad
Ahmad - avatar
2 Respuestas
+ 3
array.forEach( obj=> if (obj.routes) console.log(obj.routes))
28th Feb 2020, 12:39 AM
Gordon
Gordon - avatar
+ 3
var routes = array.filter( obj=> obj.routes).map(r=>r.routes.filter(a=>a.path)).flat(); https://code.sololearn.com/Wfl6H7UzQW03/?ref=app
28th Feb 2020, 3:24 AM
Calviղ
Calviղ - avatar