javascript filter array of objects

A modern solution with Array.prototype.filter():

const found_names = names.filter(v => v.name === "Joe" && v.age < 30);

Or if you still use jQuery, you may use jQuery.grep():

var found_names = $.grep(names, function(v) {
    return v.name === "Joe" && v.age < 30;
});

Leave a Comment