I have an array of objects as shown below:
var events = [ { date: "18-02-2016", name: "event A" }, { date: "22-02-2016", name: "event B" }, { date: "19-02-2016", name: "event C" }, { date: "22-02-2016", name: "event D" } ];
I have a date, for example "22-02-2016". How to get an array of all objects whose date is the same as a given date? So in this example I'm going to get events B and D.
UserArray.prototype.filter() is as follows:.
You can use the
filter()
function of the array:filter_dates()
Methods can be standalone, reused as in this example, or inline as anonymous methods - the choice is entirely yours =]A quick/easy alternative is a simple loop: