What is the easiest way to search a javascript object list with jQuery?
For example, I have the following js config block defined:
var ProgramExclusiveSections =
{
"Rows":
[
{ 'ProgramId': '3', 'RowId': 'trSpecialHeader'},
{ 'ProgramId': '3', 'RowId': 'trSpecialRow1' },
{ 'ProgramId': '3', 'RowId': 'trSpecialRow2' },
{ 'ProgramId': '1', 'RowId': 'trOtherInfo' }
]
}
The user has selected Program ID = 3 so I want to get only the "rows" that I have configured in this js config object for Program ID = 3. This will get me the javascript object list:
var rows = ProgramExclusiveSections.Rows
but then I need to filter this down to only where RowId = 3. What's the easiest way for me to do this with jquery?
$.grep()
var matches = $.grep(rows, function (elt)
{
return elt.ProgramId === '3';
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With