Skip to content

Instantly share code, notes, and snippets.

@devdays
Created December 22, 2014 17:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devdays/9bda346f3155751b05f5 to your computer and use it in GitHub Desktop.
Save devdays/9bda346f3155751b05f5 to your computer and use it in GitHub Desktop.
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