update object property based on previous value Object.assign

Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
0
down vote
favorite
I have one object and its keys value initialized with 0,
Now if I want to increase the value of that key from the previous value than how to do it in an efficient manner with the concept of Immutability
const nameCounter = ALPHA: 0, BETA: 0, CHARLIE: 0, PETER: 0 ;
if(condtionToIncreaeAlphaCountBy5)
Object.assign(nameCounter, ALPHA: nameCounter.ALPHA + 5 );
But it seems me very odd to write complete Object name again
What is the efficient solution to rewrite this?
ecmascript-6
add a comment |Â
up vote
0
down vote
favorite
I have one object and its keys value initialized with 0,
Now if I want to increase the value of that key from the previous value than how to do it in an efficient manner with the concept of Immutability
const nameCounter = ALPHA: 0, BETA: 0, CHARLIE: 0, PETER: 0 ;
if(condtionToIncreaeAlphaCountBy5)
Object.assign(nameCounter, ALPHA: nameCounter.ALPHA + 5 );
But it seems me very odd to write complete Object name again
What is the efficient solution to rewrite this?
ecmascript-6
If you know that alpha value is going to change, why do you useconstinstead oflet?
â LMokrane
May 31 at 5:26
I use const fornameCounternot for alpha. this is working fine. looking for to reduce theObject.assign()part
â pro.mean
May 31 at 7:16
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have one object and its keys value initialized with 0,
Now if I want to increase the value of that key from the previous value than how to do it in an efficient manner with the concept of Immutability
const nameCounter = ALPHA: 0, BETA: 0, CHARLIE: 0, PETER: 0 ;
if(condtionToIncreaeAlphaCountBy5)
Object.assign(nameCounter, ALPHA: nameCounter.ALPHA + 5 );
But it seems me very odd to write complete Object name again
What is the efficient solution to rewrite this?
ecmascript-6
I have one object and its keys value initialized with 0,
Now if I want to increase the value of that key from the previous value than how to do it in an efficient manner with the concept of Immutability
const nameCounter = ALPHA: 0, BETA: 0, CHARLIE: 0, PETER: 0 ;
if(condtionToIncreaeAlphaCountBy5)
Object.assign(nameCounter, ALPHA: nameCounter.ALPHA + 5 );
But it seems me very odd to write complete Object name again
What is the efficient solution to rewrite this?
ecmascript-6
asked May 22 at 9:06
pro.mean
1086
1086
If you know that alpha value is going to change, why do you useconstinstead oflet?
â LMokrane
May 31 at 5:26
I use const fornameCounternot for alpha. this is working fine. looking for to reduce theObject.assign()part
â pro.mean
May 31 at 7:16
add a comment |Â
If you know that alpha value is going to change, why do you useconstinstead oflet?
â LMokrane
May 31 at 5:26
I use const fornameCounternot for alpha. this is working fine. looking for to reduce theObject.assign()part
â pro.mean
May 31 at 7:16
If you know that alpha value is going to change, why do you use
const instead of let ?â LMokrane
May 31 at 5:26
If you know that alpha value is going to change, why do you use
const instead of let ?â LMokrane
May 31 at 5:26
I use const for
nameCounter not for alpha. this is working fine. looking for to reduce the Object.assign() partâ pro.mean
May 31 at 7:16
I use const for
nameCounter not for alpha. this is working fine. looking for to reduce the Object.assign() partâ pro.mean
May 31 at 7:16
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194931%2fupdate-object-property-based-on-previous-value-object-assign%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
If you know that alpha value is going to change, why do you use
constinstead oflet?â LMokrane
May 31 at 5:26
I use const for
nameCounternot for alpha. this is working fine. looking for to reduce theObject.assign()partâ pro.mean
May 31 at 7:16