I am trying to make an array with a unique Id, every time I push the id in the array is always the last index. This is the code I have tried:
locationData.forEach((data,index) => {
if(1==data.id){
data.uniqId= index
myArray.push(data)
}
});
What I get:
[{uniqId:3},[{uniqId:3},[{uniqId:3}]
What I want
[{uniqId:1},[{uniqId:2},[{uniqId:3}]