-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?

4
  • Please edit your question to show what research you have done and what attempts you've made to solve the issue yourself. Commented Aug 11, 2021 at 13:02
  • How is this question specific to angularjs? Do you want to use an angularjs 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. Commented Aug 11, 2021 at 13:07
  • Does this answer your question? JS: Filter object array for partial matches Commented Aug 11, 2021 at 13:26
  • Does this answer your question? How to filter object array based on attributes? Commented Aug 11, 2021 at 13:45

1 Answer 1

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);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.