Consider the following data structure:
const arr = [
{name:'john'},
{name:'jeff'},
{name:'bob'},
{name:'peter'},
]
arr.forEach((v,i,a)=>{
console.log(v)
})
I need to transform it into this format:
arr = [{id:1,name:john},{id:2,name:jeff},{id:3,name:bob},{id:4,name:peter}]
Each object in the array needs to have an 'id' added to it.
Can you suggest a solution for this? Thank you.