im trying to create obj called scorers in which it contains elements of the scored array and with the no. of times it exists. using for-of loop.
using:
scorers[player] ? scorers[player]++ : (scorers[player] = 1);
gives the output i want correctly
i.e.
{Lewandowski: 2, Gnarby: 1, Hummels: 1}
. but,
scorers.player ? scorers.player++ : (scorers.player = 1);
just gives object scorers with player key and 4 as value. i.e. {player: 4}
since property accessors work both by using [ ] and dot operator, why using dot method doesnt work??
scorers.player = scorers['player']
How to use . Operator to create object property and assign value
Обсуждают сегодня