First identify the entry then just add another integer to the value.
It depends on how you are updating that object now - if it's always in 0 position then just portfolioHoldings[0][amount] += number;
if not, then loop through all and check if ticker_symbol == AAPL, then update that array value, by adding needed amount.
I wouldn't want to assume that "AAPL" is always within the array.
Check first if the new item is within the array. If not, I will return and end the call (but you may wish to append this to the array instead as it is a new item).
If it is, replace the current object (or parts of the object, in this case I have done just fees & amount)
function addPortfolioItem(item) {
const index = returnPortfolioHoldingIndex(item);
if (index = -1) {
// Returning if not found - You may wish to append to the array as mentioned above
return;
} else {
// Overwrite the object within the array with the new object
portfolioHoldings[index].fees = item.fees;
portfolioHoldings[index].amount = item.amount;
}
}
function returnPortfolioHoldingIndex() {
const tickerSymbolToSearch = "AAPL";
return portfolioHoldings.findIndex(item => item.ticker_symbol === tickerSymbolToSearch);
}