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

72
Views
need to clarify things with x[y]

Can anyone explain in detail what exactly is going on in x[y] pairs? I tried console logging but no useful info. I am particularly interested in the operation within the if block.

let arr = ['a','b','b','c','c','c']
let obj = {}

arr.forEach((element) => {
    if (obj[element]){
        obj[element]++
    }else{
        obj[element] = 1
    }
})
console.log(obj) //{a: 1, b: 2, c: 3}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

so the IF blocks:

if(obj[element]) just means if element exists as a key in obj. Here, if element does not exist within obj, create a new key called element, assign it the value of 1 (currently one instance of it existing) If element exists as a key within obj, add 1 to the key element in obj (to increase the count)

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!