0

I have generated an array and now I am filtering it (with grep(), which I have never used before). Out of the matching results I need the FareIDs to display the divs that carry these IDs, but I don't know how to get to them.

function FilterFares() {

  $(".samplediv").hide();

  var matchingFares = $.grep(Fares, function(e) {
    return e.Segment == Segment && e.DepartureTime >= DepartureTime_Min && e.DepartureTime <= DepartureTime_Max;
  });

  console.log(matchingFares);          // OK
  console.log(matchingFares.FareID);   // HOW CAN I GET TO THIS VALUE ?? 

}

AND... how can I filter the same line for another Segment (in my example the Segment is 0 or 1, but there can be many more). How do I extend the grep function for that?

THANKS!

Fiddle: https://jsfiddle.net/SchweizerSchoggi/ukdmvy5e/

1 Answer 1

1

matchingFares is an array, so you need to access FareID like matchingFares[0].FareID.

This gets you every FareID:

fareIds = [];
for (fare of matchingFares) {
  fareIds.push(fare.FareID);
}
console.log(fareIds);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.