find()

as a input callback function and return true / false and print appropriate value. Find method check one by one value of array and if find get true than stop finding and print value. Ye array me se ek element ki value ko find karega or usko print kar dega. or new array dega

// const myArray = ["Hello", "catt", "dog", "lion"];

// function isLength3(string){
//     return string.length === 3;
// }

// const ans = myArray.find((string)=>string.length===3);
// console.log(ans);

const users = [
    {userId : 1, userName: "harshit"},
    {userId : 2, userName: "harsh"},
    {userId : 3, userName: "nitish"},
    {userId : 4, userName: "mohit"},
    {userId : 5, userName: "aaditya"},
];

const myUser = users.find((user)=>user.userId===3);
console.log(myUser);

Posted

in

by

Tags: