update object property based on previous value Object.assign

The name of the pictureThe name of the pictureThe name of the pictureClash 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?







share|improve this question



















  • 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

















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?







share|improve this question



















  • 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













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?







share|improve this question











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?









share|improve this question










share|improve this question




share|improve this question









asked May 22 at 9:06









pro.mean

1086




1086











  • 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

















  • 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
















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
















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation