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

261
Vistas
why genrated array with Nullish coalescing operator does not accept forEach Loop ? -- or why my Array.forEach(x=>console(x)) return an error?

Rather than my complicated explanations here are my code examples...

What did I miss on

(objX[elmX] ?? [400]).forEach(x=>{ console.log(x) })
or
(objX[elmY] ?? [400]).forEach(y=>{ console.log(y) })
lines ?

const objX = 
  { 'aa' : [ 101, 102, 103 ] 
  , 'bb' : [ 201, 202, 203 ]
  , 'cc' : [ 301, 302, 303 ]  
  } 

const elmX = 'bb' // valid key for objX
const elmY = 'yy' // invalid key for objX


console.log("objX[elmX] -->", JSON.stringify(objX[elmX] ?? [400])  ) // [ 201, 202, 203 ]
console.log("objX[elmY] -->", JSON.stringify(objX[elmY] ?? [400])  ) //  [400]
 
console.log( '? isArray( elmX )', Array.isArray( (objX[elmX] ?? [400]) ))  // true
console.log( '? isArray( elmY )', Array.isArray( (objX[elmY] ?? [400]) ))  // true

console.log( '? length( elmX )', (objX[elmX] ?? [400]).length )  // 3
console.log( '? length( elmY )', (objX[elmY] ?? [400]).length )  // 0

let arrX = objX[elmX] ?? [400]  // 


console.log( '- elmX - arrX -------->')
arrX.forEach(x=>{ console.log(x) })
console.log( '----------------<')

console.log( '- elmX ---------------->')
(objX[elmX] ?? [400]).forEach(x=>{ console.log(x) })  // --> error console.log(...) is not a function
console.log( '----------------<')

console.log( '- elmY --------------->')
(objX[elmY] ?? [400]).forEach(y=>{ console.log(y) })  // --> error console.log(...) is not a function
console.log( '----------------<')
 
.as-console-wrapper {max-height: 100%!important;top:0 }

about 4 years ago · Juan Pablo Isaza
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