Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to filter javascript array using substring search for key and value pair

in the below array i want to filter out records, that match the substring "11/2022" for key StartTime

[
  {
    StartTime: '17/10/2022 14:45',
    Duration: '000:00:44:32',
  },
  {
    StartTime: '17/11/2022 14:45',
    Duration: '000:00:44:30',
 
  },
  {
    StartTime: '18/11/2022 14:45',
    Duration: '000:00:44:30',
 
  },  
   {
    StartTime: '17/12/2022 14:45',
    Duration: '000:00:44:30',
 
  }
]

expected output:

[
   {
    StartTime: '17/11/2022 14:45',
    Duration: '000:00:44:30',
 
  },
   {
    StartTime: '18/11/2022 14:45',
    Duration: '000:00:44:30',
 
  }
   
]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

you can use the includes function like this

[
    { StartTime: "17/10/2022 14:45", Duration: "000:00:44:32" },
    { StartTime: "17/11/2022 14:45", Duration: "000:00:44:30" },
    { StartTime: "18/11/2022 14:45", Duration: "000:00:44:30" },
    { StartTime: "17/12/2022 14:45", Duration: "000:00:44:30" },
  ].filter((item) => item.StartTime.includes("11/2022"));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading