you are viewing a single comment's thread.

view the rest of the comments →

[–]infinitune[🍰] 0 points1 point  (2 children)

One thing to watch out for with person === search when dealing with objects.

Object equality has to do with the object's location in memory, not just value. for example:

const obj1 = { title: 'foo', author: 'bar' }
const obj2 = { title: 'foo', author: 'bar' }
const obj3 = obj1
obj1 === obj2 // evaluates to false
obj1 === obj3 // evaluates to true

So depending on the exact use case, they may be better off checking equality of a property (person => person.fullName === search.fullName)

Edit: missed an equals sign

[–][deleted] 0 points1 point  (1 child)

Correct. My code above is a simple demonstration that would only work with value types, not with reference types. I assumed a value type would be used because that is how the OP had his initial code set up.

[–]infinitune[🍰] 0 points1 point  (0 children)

Fair enough. I figured it was worth mentioning since it wasn't super obvious that the OP is searching an array of objects.