[Solved] Get key/id from array of objects


Assuming records looks like this (since you didn’t provide it) :

let records = [
  {
     id : 1,
     time : 10
  },
  {
     id : 2,
     time : 20
  }
]

then you can simply get the index of the matched object this way :

 let records = [
      {
         id : 1,
         time : 10
      },
      {
         id : 2,
         time : 20
      }
    ],
    tmp_date = 20,
    index;
    
for(let i in records){
  if(records[i].time===tmp_date){
    index = i;
    break;
  }
}

console.log(`Found time ${tmp_date} at index ${index}.`)

1

solved Get key/id from array of objects