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

81
Vistas
String to array object in javascript

I have a string like this:

var x = "[{"id": "40", "text": "Budi "}, {"id": "47", "text": "Staff 01"}]"

I expect to loop until end and read the id and text one by one, how to do this in javascript?

I have tried below:

var myArr = JSON.parse(x);
for (var i in myArr) {
     alert(myArr[i]);
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Your JavaScript is invalid. Make sure to wrap it in single quotes.

var x = '[{"id": "40", "text": "Budi "}, {"id": "47", "text": "Staff 01"}]'
var myArr = JSON.parse(x);
for (var i in myArr) {
     console.log("id: " + myArr[i].id);
     console.log("text: " + myArr[i].text);
}

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