Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
jQuery Grep Example
// Get just the toys by grep on products
var toys = $.grep(myData.products, function (element, index) {
// return whether myData.products.category == 'Toy'
return element.category == "Toy";
// toys is a new array of the matching products
$.each(toys, function (i) {
$('#toys').append("<li class='toy'>" + toys[i].name + "</li>");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment