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

237
Vistas
Return specific key (field) from fetch api response object

Fetching a word from this API(https://api.dicionario-aberto.net/random) gives me the whole object:

{
  "word": "linguaraz",
  "wid": 74891,
  "sense": 1
}

How can I get to return only the word value in this object?

This is my code:

const getWord = async function () {
    const response = await fetch ("https://api.dicionario-aberto.net/random?get.value")
    const words = await response.text();
    const wordArray = words.split("\n");
    const randomIndex = Math.floor(Math.random() * wordArray.length);
    word = wordArray[randomIndex].trim();
    placeholder(word);
};
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You need to convert your api result into JSON first instead of text, then it will be easier to access word, like this

async function getData(){
   res = await fetch('https://api.dicionario-aberto.net/random');
   data = await res.json();
   console.log(data.word);
}
getData();
about 4 years ago · Juan Pablo Isaza Denunciar

0

Convert fetch data to json and read it as object property:

const getWord = async function () {
  const response = await fetch ("https://api.dicionario-aberto.net/random?get.value")
  const words = await response.json();
  placeholder(word);
};
about 4 years ago · Juan Pablo Isaza Denunciar

0

Convert to JSON using:

const obj = JSON.parse(await response)

or

const obj = await response.json()

Get value by entering key:

obj.<key_name>
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