0

I need to find the index of a value in an object in a two dimensional array. The array is structured like this:

trips.push({
    station: stationIDs[i],
    stationtrips: ({
        [theid]: station[theid], // This is what I need to find the Index of
        cnt: station.cnt,
        tps: station.tps
    })
})

What I tried so far:

// First Find index of station
stationIndex = trips.findIndex(y => y.station == stationIDs[i]);
// If exists, find index of sub-station
if(stationIndex !== -1) {
    subStationIndex = trips[stationIndex].stationtrips.findIndex(x => x[theid] == station[theid]);

}

I am getting this error:

trips[stationIndex].stationtrips.findIndex is not a function

Question: Does findIndex not work with this structure? What is the proper way to handle this?

-- Update: The console.log of the array (up until it finds a stationindex and then fails at the substationindex):

enter image description here

ffritz
  • 2,180
  • 1
  • 28
  • 64

0 Answers0