I have an array of objects . I need to convert the value of the 'key' by incrementing count .
lets say I have an array
const arr1=[{key:'a', val:1},{key:'b',val:2}]
I want to give an incrementing key value to each key
I have tried the below code but couldn't override the count value
let count = 0;
const arr1=[{key:'a', val:1},{key:'b',val:2}]
arr1.map(el => el.key=count+1);
console.log(arr1)
Expected Result :
[ { key: 1, val: 1 }, { key: 2, val: 2 } ]