1

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

Samuel Lawrence
  • 253
  • 2
  • 12

1 Answers1

0

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

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

Muhammed Jaseem
  • 782
  • 6
  • 18