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

115
Views
Anidado para... de iterar sobre el primer elemento de matriz

Tengo una estructura de datos como esta

 const array = [ [["first_name" , "First"], ["image" , "image"]], [["email" , "email"]], [["last_name","last_name"]], [["password" , "password"], ["password", "password"]] ]

La implementación de mi iterador es

 let arr = array.values(); let obj = { [Symbol.iterator]: function () { return { next() { for (const iterator of arr) { for (let [, value] of iterator) { return { done: false, value, }; } } return { done: true, }; }, }; }, }

Pero cuando lo itero [...obj]

Obtengo solo el primer elemento de la matriz 2D

El resultado que obtengo es ["First" , "email" , "last_name" , "password"]

Salida esperada ["First" , "image" , "email" , "last_name" , "password", "password"]

Anidado para ... en iterar solo el primer elemento de la matriz anidada

Nota: - La solución anterior funciona bien con la función de generador Symbol.Iterator

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

0

Al igual que la respuesta de Nenad Vracar, dado que se devuelve desde la instrucción de bucle for interna, no repite todas las matrices internas, solo la matriz externa se repite y finaliza.

Los estados individuales deben poder guardarse para implementar lo que desea con Symbol.iterator solo sin usar Generator .

 const array = [ [["first_name" , "First"], ["image" , "image"]], [["email" , "email"]], [["last_name","last_name"]], [["password" , "password"], ["password", "password"]] ]; const obj = { [Symbol.iterator]: () => { return { stack: [...array], target: [], next() { if (!this.target.length && !this.stack.length) return { done: true, value: undefined, } if (!this.target.length) this.target = this.stack.shift(); return { done: false, value: this.target.shift()[1], }; }, } } }; console.log([...obj]); // ['First', 'image', 'email', 'last_name', 'password', 'password']
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!