by Sai gowtham

Array.some() method in JavaScript

The some( ) method executes the callback function on each element present in the array and returns true immediately if at least one element passes the test condition otherwise it returns false.

const users = [

    { id:1,user:"gowtham"},
    {id:2,user:"king"},
    {id:3,user:"nick"},
]


console.log(users.some(user=>user.id === 2)) //  true


console.log(users.some(user=>user.id === 10)) //  false

To check whether an email is available or not

const emails = [
     "example1@gmail.com",
     "example2@gmail.com",
     "example3@gmail.com",
]



console.log(emails.some(email=>email === "example3@gmail.com")) // true

console.log(emails.some(email=>email === "example10@gmail.com")) // false

Note: The some() method executes the callback function until it finds the truthy value otherwise it returns false.

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
Vue JS 2 - The Complete Guide (incl. Vue Router & Vuex)
130,921 students enrolled
21 hours of video content
View Course