i am trying to return the sum of the first 4 grid values from the object below (expected output 5)
[
{
"id": 1,
"grid": 1
},
{
"id": 2,
"grid": 2
},
{
"id": 3,
"grid": 1
},
{
"id": 4,
"grid": 1
},
{
"id": 5,
"grid": 1
}
]
data.map(item => {
console.log(item.grid);
});
Relatively new with .map, I would usually use a forwhile iterator but wondered if someone could suggest a more es6 style pattern for solving the problem.