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

177
Visualizações
Getting only a value from a JSON string in JavaScript

I am sorry this seems like an easy answer but I am not really good at programming, I am trying to get a value from an API, I can get the JSON but I only need one value and the other is unnecessary, this is the JSON: https://www.dnd5eapi.co/api/monsters/ =>

"results": [
{
"index": "aboleth",
"name": "Aboleth",
"url": "/api/monsters/aboleth"
},
{
"index": "acolyte",
"name": "Acolyte",
"url": "/api/monsters/acolyte"
},
{
"index": "adult-black-dragon",
"name": "Adult Black Dragon",
"url": "/api/monsters/adult-black-dragon"
}]

and so on,

I am only trying to get the index of each one.

Thank you in advance.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can convert it to an object pull the data that you need.

const data = JSON.parse(results) // Assuming the variable containing your json is called results

// Make an array of only the indexes
const indexes = data.results.map(v => v.index)

Update: OP Requested

      const uri = "https://www.dnd5eapi.co/api/monsters/";
      // Promises
      fetch(uri)
        .then((res) => res.json())
        .then((data) => {
          const indexes = data.results.map((v) => v.index);
          console.log(indexes);
        });
      // Async Await
      async function getData() {
        const res = await fetch(uri);
        const data = await res.json();
        const indexes = data.results.map((v) => v.index);
        console.log(indexes);
      }
      getData()
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