I've searched many examples on this site but can't seem to fit them into my needs. I just need to filter some JSON results using grep().
Below is my JSON:
var data = { "items": [
{
"id": 1,
"category": "cat1"
},
{
"id": 2,
"category": "cat2"
},
{
"id": 3,
"category": "cat1"
}
]}
With the example above
- how would I return all items with the category of
cat1? - how would I return all items with the category of
cat1andidof 3 ?
I know this isn't a great example but any help would be awesome! Thanks!
I have tried variations of the following
data.items = $.grep(data.items, function(element, index) {
return element.id == 1;
console.log(data.items);
});
console.log(), I fail to see the issue in your example.