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

252
Views
¿Por qué la matriz generada con el operador coalescente nulo no acepta forEach Loop? -- o ¿por qué mi Array.forEach(x=>console(x)) devuelve un error?

En lugar de mis explicaciones complicadas aquí están mis ejemplos de código...

¿Qué me perdí?

(objX[elmX] ?? [400]).forEach(x=>{ console.log(x) })
o
(objX[elmY] ?? [400]).forEach(y=>{ console.log(y) })
líneas ?

 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
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!