Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

77
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda