Javascript Nuggets

MAP

Map:- Map is a higher-order function that is going to iterate from the original array essentially we can return whatever we would want.

- The Map() function is used for creating the new array from the existing array and does not change the size of the original array.

-. The map() function takes a callback function as an argument, which is executed for each element of the array - uses values from the original array.



const people = [

    {
        name: "Rob",
        age: 25,
        job: "Teacher"
    },

    {
        name: "BOb",
        age: 25,
        job: "Mechanic"
    },
    {
        name: "Roddie",
        age: 28,
        job: "Engineer"
    }

]

const liveData = people.map((item) => { // item is a callback function and it could be antything with name like value
   return{
    firstName: item.name.toUpperCase(),
    ages:item.age+20
   }

});
console.log(liveData)