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

175
Vistas
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 Respuestas
Responde la pregunta

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 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