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

167
Vistas
How to get JSON Array value? I need to get murali printed
<!DOCTYPE html>
<html>
<body>

<h2>Creating an Array from JSON</h2>
<p id="demo"></p>

<script>
const myJSON = '[{password:"murali"}]';
const myArray = JSON.parse(myJSON).password;
document.getElementById("demo").innerHTML = myArray;
</script>

</body>
</html>

I need to get murali to get printed. This is for my React Project. I got to validate password. Hence I connected my mysql and retrive password from database and I need to validate it, In oder to validate I need to compare (database Password == input password). But as i retrive password I got the password in [{password: "murali"}] in this format and I am not able to compare with input password.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I did not understand how the front-end code articulate with the back-end code, but to your simple question, you need to:

  • name your variable correctly, myArray seems to be a password and not an array
  • use double quotes for json keys
  • access array with an index

Fixed, this code will print the password.

const jsonString = '[{"password":"murali"}]';
const json = JSON.parse(jsonString);
const password = json[0].password;
document.getElementById("demo").innerHTML = password;
<div id="demo"></div>

about 4 years ago · Juan Pablo Isaza Denunciar

0

Just pointing out the issues preventing the code from running:

  1. The JSON string format is incorrect.
  2. The password object is the first item in an array so it must be retrieved using an index.
const myJSON = '[{"password":"murali"}]';       // <-- add double quotes to key
const myArray = JSON.parse(myJSON)[0].password; // <-- add array index 
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