2016-03-14

jQuery - How to filter an array of json objects

$.grep(
    ARRAY_OF_OBJECTS
    , function(obj) {
        return(
            obj.OBJECT_KEY_1 === SOUGHT_VALUE_1
            && obj.OBJECT_KEY_2 === SOUGHT_VALUE_2
        );
    }
).length;

PS. Add the .length property call if you just want to know how many sub-objects matched your query.

No comments:

Post a Comment