impactbyte-drogon-scholarship / discussion

General Discussion
https://glints.id
The Unlicense
2 stars 0 forks source link

Differentiate between map and forEach, using destructuring #17

Open mhaidarhanif opened 6 years ago

mhaidarhanif commented 6 years ago
const PEOPLE = [
    {
        id: 0,
        name: "Haidar",
        phoneNumber: "+62-8-1993-101010"
    },
    {
        id: 1,
        name: "Hanif",
        phoneNumber: "+62-878-8055-1650"
    }
];

PEOPLE.forEach(({ name, phoneNumber }) => {
    console.log(name, phoneNumber);
});

const MAPPED_DATA = PEOPLE.map(({ name, phoneNumber }) => {
    return {
        name: name,
        phone: phoneNumber
    };
});

console.log(MAPPED_DATA);