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

335
Views
Cómo extraer el último elemento de una cadena json no válida con js

Estoy usando una API de reconocimiento de voz de nodejs que devuelve una cadena con varios textos dentro de una estructura similar a JSON que no es válida ni utilizable

 { "text": "Play" } { "text": "Play astronaut" } { "text": "Play astronaut in the" } { "text": "Play astronaut in the ocean" } { "entities": {}, "intents": [], "text": "Play astronaut in the ocean.", "traits": {} }

y solo quiero el último elemento que es

 { "entities": {}, "intents": [], "text": "Play astronaut in the ocean.", "traits": {} }

filtrándolo o algo así para extraer el texto "Juega astronauta en el océano".

La API siempre genera múltiples elementos de texto en diferentes cantidades cada vez, pero quiero que el último elemento sea posible. ¿O debería encontrar una API diferente que se pueda usar?

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

0

Suponiendo que la respuesta se devuelva como una matriz, es decir, [{ "texto": "Reproducir"}, {siguiente...}], etc.

Luego puede obtener el último elemento en la matriz variabilizando la matriz, obtener su longitud y encontrar el último objeto.

p.ej

 const x = [{ text.. }, { text.. }] const lastItem = x[x.length - 1]

Luego, si también desea encontrar el último elemento dentro de ese objeto, también puede hacerlo con Object.values

 const lastItemObject = Object.values(lastItem) const lastItemInTheObject = lastItemObject[lastItemObject.length - 1]
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!