Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
javascript hashmap one line modify or create

I want to know if there is a clean way to modify a value in a hashmap or create it if it doesn't exist without doing an if block. Example of what i'm currently doing

let dict = {}
if(dict['key']){
 dict['key'] += 1
} else {
 dict['key'] = 1
}

Want to know if there is a cleaner way to do what I did above.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use dot notation, because the property isn't dynamic, and alternate dict.key with 0 before adding 1.

dict.key = (dict.key || 0) + 1;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!