this might be a dumb question but I was curious if it is faster to use strict comparisons between objects than to compare an identifying property, i.e. an id.
Let's say I have these two functions, which tries to remove an object from an array that they belong to:
// The objects in this array all have unique string `id`s, in addition to other props.
const removeObject = (array, object) => {
const index = array.findIndex(o => o === object)
array.splice(index, 1)
return object
}
const removeObjectUsingId = (array, object) => {
const index = array.findIndex(o => o.id === object.id)
array.splice(index, 1)
return object
}
Assuming that this operation will be done frequently on large arrays, magnifying the difference between the two comparison operations. Am I right to think that since object comparison is done through comparing the reference (maybe the address?) of the object, it would be faster than comparing two strings?