Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda