.find() Is finding values elements that are not apart of the search criteria

Viewed 24

I am using .find() on the following json object, which I've named records:

[
  {
    "_id": "61f9da9fcc6888f201f722cb",
    "firstName": "joe",
    "lastName": "jergen",
    "email": "joe@outlook.com",
    "status": "active",
    "amount": "5600"
  }
]

I then try to find a user in my object using find():

let userProfile = records.find((x) => (x.email = "peter@google.com"));

When I log userProfile it seems to pull joe@outlook.com still even though the user is not in the object. The desired behaviour would be null/undefined

1 Answers

You probably want to do x.email === "peter@google.com"

= is an assignment operator while === is a comparison operator.

Related