I have an array of objects like this:
const data = [
{name: 'Page A', count: 4000},
{name: 'Page B', count: 3000},
{name: 'Page C', count: 2000},
];
I need to add an index number to the count property so the list would look like this:
const wantedArray = [
{name: 'Page A', count1: 4000},
{name: 'Page B', count2: 3000},
{name: 'Page C', count3: 2000},
];
I tried this but got this ts error: Operator '+' cannot be applied to types '{ name: any; count: any; }' and 'number'.ts(2365)
let wantedArray: any = []
data.map((object: any, index) => {
wantedArray.push({
name: object.name,
count+index: start.count,
});
});
What is the best solution to achieve this? Thank you.