jeudi 23 novembre 2017

How to find an object with a certain property value in an array?

I have an array of objects:

var allButtons = [
    buttonA,
    buttonВ,
    buttonС,
    "->"
];

This objects can have the property 'hidden' which can be true or false.

I need to discover (in an optimal way), whether any of this 'buttons' have hidden === false (in other words, are visible).

Now i use this primitive approach:

someOfButtonsIsVisible = false;

Ext.each(allButtons, function (item){
    if(item.hidden === false) {
        someOfButtonsIsVisible = true;
    }
});

But in this case i have to go through all objects and check their 'hidden' property.

Is there a better way to know whether any of objects in array have hidden === false?




Aucun commentaire:

Enregistrer un commentaire