I'm trying to dynamically add additional property in the existing object. This is what I have:
let items = [
{name: 'Carlsberg', category: 'Beer', price: '4.99'},
{name: 'Smirnoff', category: 'Vodka', price: '28.99'},
{name: 'Miller Lite', category: 'Beer', price: '7.99'}
]
These are the object properties which I wish to add:
categories:{
beerCounter:2,
vodkaCounter:1,
}
And what I want is to dynamically add additional properties of an object to look like this:
items = [
{name: 'Carlsberg', category: 'Beer', price: '4.99', counter: categories.beerCounter},
{name: 'Smirnoff', category: 'Vodka', price: '28.99', counter: categories.vodkaCounter},
{name: 'Miller Lite', category: 'Beer', price: '7.99', counter: categories.beerCounter}
]
Array.mapcan modify the original object..${obj.category.toLowerCase()}Counter])