I am using following function to add index to each array object but all id get same value when I check console.log
var foo = [...this.props.articleList];
foo.forEach(function(row, index) {
row.id = index+1;
});
console.log(foo);
I want something like this =>
[{…}, {…}, {…}, {…}, id: 1], [{…}, {…}, {…}, {…}, id: 2], [{…}, {…}, {…}, {…}, id: 3]
but it is returning
[{…}, {…}, {…}, {…}, id: 3], [{…}, {…}, {…}, {…}, id: 3], [{…}, {…}, {…}, {…}, id: 3]