Created
December 22, 2014 17:28
-
-
Save devdays/9bda346f3155751b05f5 to your computer and use it in GitHub Desktop.
jQuery Grep Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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