i have this array of objects
data= [
{ name: "name1",
email: "email1@gmail.com"},
{ name: "name2",
email: "email2@gmail.com"},
{ name: "name3",
email: "email3@gmail.com"},
]
i have the email on one of the users
"email2@gmail.com"
i want to redirect the user in the users page if his email exist in the data array else redirect him to register page
>Solution :
const data= [
{ name: "name1",
email: "email1@gmail.com"},
{ name: "name2",
email: "email2@gmail.com"},
{ name: "name3",
email: "email3@gmail.com"},
]
const email = "email2@gmail.com"
console.log(data.some(item => item.email === email))
returns true if found.
replace some with find to get the first element that matches