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

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

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