我正在将一些代码从Python转换为JavaScript,并且需要重写以下嵌套的for循环列表理解(其中solution是字符串键和列表值的字典)。[e for key in solution.keys() for c in solution[key] for e in c.events]
在没有过多考虑的情况下,我会把它转换成像这样笨重、丑陋的嵌套for循环。如何用简短的、惯用的、现代的(ES2015+) JavaScript重写上面的嵌套for循环
,{id:4, children:[{id:5, children:[{id:6, children:[]}]}]} // Two levels of children etc...所以,当循环遍历array.length; i++){ array[i].children.push(element);}
因此,问题是如何循环遍历所有这些可能级别的子级