如何在复杂的javaScript数组对象中搜索
我有点困惑。我在指令中有以下代码:如何在复杂的javaScript数组对象中搜索,javascript,angularjs,lodash,Javascript,Angularjs,Lodash,我有点困惑。我在指令中有以下代码: NavTabsDirective.prototype.addPane=函数(窗格){ if(!.isObject(pane)| |“pane”!==pane.constructor.name){ 抛出新类型错误(“窗格必须是窗格的实例”); } 如果(u.isUndefined(this.FirstPane)){ this.FirstPane=窗格; } this.Panes[pane.name]=窗格; };在这里检查了几个线程后,找到了一个解决方案:
NavTabsDirective.prototype.addPane=函数(窗格){
if(!.isObject(pane)| |“pane”!==pane.constructor.name){
抛出新类型错误(“窗格必须是窗格的实例”);
}
如果(u.isUndefined(this.FirstPane)){
this.FirstPane=窗格;
}
this.Panes[pane.name]=窗格;
};代码>在这里检查了几个线程后,找到了一个解决方案:
for(让窗格在此.Panes中){
if(this.Panes[pane].isValid==false){
无效=真;
打破
}
}
var Panes=[“你好”,“世界”];
var PanesLength=Panes.length;
对于(变量i=0;i }
除非窗格。name
是此窗格中的数字。窗格不是数组,而是对象,您可以使用其键并将其减小为值:
const result = Object.keys(this.Panes).reduce(
(all,key)=>all && this.Panes[key].isValid,
true
)
昨晚我想出了一个类似的解决方案,看看我自己的答案。我必须稍微调整它,并传回无效选项卡的数组,不仅仅是状态,而是用于循环。