Write a example for jquery.grep method run on json array
Below is the example for jquery.grep method which apply filter on the json array
var dataarray = {
"itemval": [{
"id": 1,
"category": "option1"
}, {
"id": 2,
"category": "option2"
}, {
"id": 3,
"category": "option1"
}]
};
var returnedvalue = $.grep(dataarray.itemval, function (element, index) {
return element.id == 1;
});
alert(returnedvalue[0].id + " " + returnedvalue[0].category);
| |