-4

I have the following array:

[
  {
    Id: 1,
    Name: "AI",
    Capacity: 2,
    From: "2021-10-27T08:00:00",
    To: "2021-10-27T08:50:00",
  },
  {
    Id: 2,
    Name: "TEST",
    Capacity: 2,
    From: "2021-10-28T09:10:00",
    To: "2021-10-28T09:20:00",
  },
]

How can I filter my results to only get items where the From property includes 2021-10-28?

Behemoth
  • 5,389
  • 4
  • 16
  • 40
Deko
  • 61
  • 1
  • 7
  • Please [edit] your question to show what research you have done and what attempts you've made to solve the issue yourself. – Heretic Monkey Aug 11 '21 at 13:02
  • How is this question specific to angularjs? Do you want to use an [angularjs filter](https://docs.angularjs.org/api/ng/filter/filter) or are you looking for a pure javascript approach? Either way change up your browser search terms to reflect that and you should come across multiple answers on how to do this. – Igor Aug 11 '21 at 13:07
  • Does this answer your question? [JS: Filter object array for partial matches](https://stackoverflow.com/questions/42035717/js-filter-object-array-for-partial-matches) – Heretic Monkey Aug 11 '21 at 13:26
  • Does this answer your question? [How to filter object array based on attributes?](https://stackoverflow.com/questions/2722159/how-to-filter-object-array-based-on-attributes) – Behemoth Aug 11 '21 at 13:45

1 Answers1

0

Try this:

const data = [{
    "Id": 1,
    "Name": "AI",
    "Capacity": 2,
    "From": "2021-10-27T08:00:00",
    "To": "2021-10-27T08:50:00"
  },
  {
    "Id": 2,
    "Name": "TEST",
    "Capacity": 2,
    "From": "2021-10-28T09:10:00",
    "To": "2021-10-28T09:20:00"
  }
];

const result = data.filter((e) => e.From.slice(0, 10) === "2021-10-28");
console.log(result);
Behemoth
  • 5,389
  • 4
  • 16
  • 40