Given a JSON object like:
var data = {items: [
{value: "21", name: "Mick Jagger"},
{value: "43", name: "Johnny Storm"},
{value: "46", name: "Richard Hatch"},
{value: "54", name: "Kelly Slater"},
{value: "55", name: "Rudy Hamilton"},
{value: "79", name: "Michael Jordan"}
]};
How can I do something like this:
datagood = data.where(value == 55)
Is something like that possible with JS/jQuery? Thanks
jQuery's grep
function lets you filter through an array:
var datagood = $.grep(data.items, function (item) {
return item.value == 55;
});
If you want more powerful utilities, take a look at this SO question on JS LINQ libraries.
Alternatively, underscore.js is also useful for array/object manipulation.
jLinq? http://www.hugoware.net/Projects/jLinq
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