For instance:
items: object[] = [
{name: 'Backpack', weight: 2.5},
{name: 'Flashlight', weight: 0.8},
{name: 'Map', weight: 0.3}
];
I prefer the items to have an 'age' property as well:
itemList: object[] = [
{name: 'Backpack', weight: 2.5, age: 10},
{name: 'Flashlight', weight: 0.8, age: 15},
{name: 'Map', weight: 0.3, age: 20}
]
I understand that I could iterate over each item and assign an age like this:
for(let i=0; i<items.length; i++){
items[i].age = i * 5 + 10;
}
However, this method assigns ages in a linear sequence. Is there a more efficient way to achieve this?