What the question says...
Does jQuery have any methods that will allow you to query a mult-dimensional array of objects in a similar fashion as it does with the DOM.
You can't use selector syntax, but jQuery comes with $.grep and $.inArray, which can be useful for this. grep
returns a new array of elements that match a predicate. inArray
returns the index of the first matching element, or -1. For instance:
var matches = $.grep(array, function(el){
return el.StartOfPeriod > 2000;
});
These are similar to the standard ECMAScript methods, Array.filter (simimlar to grep
) and Array.indexOf (similar to inArray
); jQuery actually uses Array.indexOf
where available. There are also other useful ECMAScript methods, such as Array.every (all elements matching) and Array.some (at least one matching). MDC has code you can add to your project so these work in browsers that don't have native implementations.