forEach()

input a callback function and print index or value. ye array ki value ko iterate karega or index and value ko print karega.

const users = [
    {firstName: "harshit", age: 23},
    {firstName: "mohit", age: 21},
    {firstName: "nitish", age: 22},
    {firstName: "garima", age: 20},
]

// users.forEach(function(user){
//     console.log(user.firstName);
// });

 users.forEach((user, index)=>{
     console.log(user.firstName, index);
 })

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *