Dhanush K

Dhanush K

  • 529
  • 2.2k
  • 168.9k

How to find array index for Date type in TypeScript?

May 16 2022 5:13 PM

I need to find the index for an array of type Date. Is it possible to declare date directly or I have to convert it to string? If converted to string how to find the index of that? If possible please provide any example for that..

Like the one below,

interface Users {
  id: number;
  name: string;
}
let exampleArrObj: Array = [
  { id: 1, name: 'infinitbility' },
  { id: 2, name: 'notebility' },
  { id: 3, name: 'repairbility' },
];let objIndex = exampleArrObj.findIndex((e: Users) => e.name == 'notebility');
console.log('exampleArrObj index', objIndex);

Here they have given id of type number and name of type string

The output for above code will be:  exampleArrObj index 1 

How can I add date type and find the index for that?


Answers (1)