Original array is newData
. I wanted add one more array element to newData and added array Element should have Rank 1
.
Issue is Rank is getting updated to 1 for both the records. Rank should be 1 for second record and 1st record should be null
Please tell me what i'm doing wrong here.
let newData = [{
"key1": {
"cc":'IND'
},
"key2": {
"rank": null
}
}];
let setData = newData.concat(newData.slice());
setData.forEach(data => {
data.key2.rank =+ 1;
});