Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!