I have a large VueJS app with a ton of data. Different views perform various operations on arrays of objects. I've created basic lookup arrays to find object.id in the various object arrays. What I'd like to do now is create a sorted array of object ids according to a field or fields. For example, updated_at. I think I'm overcomplicating this. I was hoping to have something like this:
let indexedByUpdatedAt = {}
objects.sort((a,b) => new Date(a.updated_at) - new Date(b.updated_at))
.forEach((object) => {
indexedByUpdatedAt[object.updated_at] = object.id
})
When new data comes in, I would have to update the array, but new data 99% of the time could just be pushed or shifted onto the array so I wouldn't have to re-index everything. Even in the case of inserting in the middle of the array, I could traverse up to a value rather than completely rechecking the array. Bad idea right?