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

126
Views
¿Cómo extraer una matriz de objetos anidados profundamente y pasar al estado React Hook?

Tengo una matriz de 49 objetos en total. Dentro de cada objeto anidado, hay otra matriz " niños " anidada. Y dentro de esta matriz, hay un valor de " texto ".

Estoy tratando de mapear y filtrar estos valores solo, para concatenar/combinar el texto y moverlos a mi React Hook. De esta manera, solo me queda texto para poder calcular el tiempo de lectura en función de la cantidad de contenido textual.

Mi gancho:

 const [textSize, setTextSize] = useState();

Ejemplo de 4 de 49 objetos:

 0: {_key: 'ade9a24f5cb6', _type: 'block', caption: null, children: Array(1), markDefs: Array(0), …} 1: {_key: '5aa8a2fa2969', _type: 'block', caption: null, children: Array(1), markDefs: Array(0), …} 2: {_key: '602703f9c2b7', _type: 'block', caption: null, children: Array(1), markDefs: Array(0), …} 3: {_key: '211597e8045a', _type: 'block', caption: null, children: Array(1), markDefs: Array(0), …}

Dentro de uno de los arreglos "niños":

 0: {_key: '76f4ec1ed87f', _type: 'span', marks: Array(0), text: 'Lorem ipsum dolor sit amet'}

y de esa matriz, necesito el texto de cada objeto si eso tiene sentido.

La matriz tiene 49 objetos => Cada objeto tiene una matriz anidada (hijos) => Cada matriz de niños tiene el valor "texto".

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

0

¿Qué tal algo como esto? Si estoy entendiendo bien tu problema...

 let array = [ {_key: 'ade9a24f5cb6', _type: 'block', caption: null, children: [ {_key: '76f4ec1ed87f', _type: 'span', marks: Array(0), text: '1 Lorem ipsum dolor sit amet'}, {_key: '76f4ec1ed87f', _type: 'span', marks: Array(0), text: '2 Lorem ipsum dolor sit amet'} ], markDefs: Array(0) }, {_key: '5aa8a2fa2969', _type: 'block', caption: null, children: [ {_key: '76f4ec1ed87f', _type: 'span', marks: Array(0), text: '3 Lorem ipsum dolor sit amet'} ], markDefs: Array(0) }, {_key: '602703f9c2b7', _type: 'block', caption: null, children: [ {_key: '76f4ec1ed87f', _type: 'span', marks: Array(0), text: '4 Lorem ipsum dolor sit amet'}, {_key: '76f4ec1ed87f', _type: 'span', marks: Array(0), text: '5 Lorem ipsum dolor sit amet'}, {_key: '76f4ec1ed87f', _type: 'span', marks: Array(0), text: '6 Lorem ipsum dolor sit amet'}, ], markDefs: Array(0) }, {_key: '211597e8045a', _type: 'block', caption: null, children: [], markDefs: Array(0) } ] let results = array.map(x => x.children).flat().map(y => y.text); console.log(results);

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!