Here is some code: function search(query) { return results.filter(r => r.matches(query)); } The variable searchResults contains the output.