Remove objects from a javascript array

+2 votes
asked Dec 13, 2012 in java script by jonathan (3,105 points)


I have an array that is populated using some xpath; so the items in the array could be as little as 1-20+.

I am populating it like so:

    var masterPath = $('items item', response.responseXML)
    masterPath.each(function (index, obj) {
    var assignments = $('> data > title', obj).text();

However, the xml is a bit different for each, ie




What I need is to only grab the latter two items (the 'data' that contains both a 'duedate' AND an 'availdate'.)

What would be the best way to go through all tags that may exist in the xml, and then only grab the ones with duedates and availdates and put them into the array?

1 Answer

0 votes
answered Dec 13, 2012 by arthi (1,110 points)

You want a different selector: This one selects only <data> items which have both a <duedate> and <availdate>:

$("> data:has(duedate):has(availdate) > title", obj)