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

146
Views
How to I pull just the 'results' from this API data?

I am trying to pull just the results from the below API. However it seems to be nested within some data and would like to extract it.

https://opentdb.com/api.php?amount=10000

How can it be done so that I only pull the results and that becomes my 'quizArray' useState?

import './App.css';

const url = 'https://opentdb.com/api.php?amount=10000';

function App() {
  const [quizArray, setQuizArray] = useState([]);

  const fetchData = async () => {
    const response = await fetch(url);
    const quiz = response.json();
    setQuizArray(quiz);
  }

  useEffect (() => {
    fetchData()
  }, [])
  console.log(quizArray)


  return (
    <div className="App">

    </div>
  );
}

export default App;```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your API URL returns have below response structure

{
"response_code": 0,
"results": []
}

To take out only the results key you can use dot(.) notation

obj.results will give you the quiz array of the objects


import './App.css';

const url = 'https://opentdb.com/api.php?amount=10000';

function App() {
  const [quizArray, setQuizArray] = useState([]);

  const fetchData = async () => {
    const response = await fetch(URL).then(res=>res.json()); // MODIFY THIS LINE
    const quiz = response.results;// MODIFY THIS LINE
    setQuizArray(quiz);
  }

  useEffect (() => {
    fetchData()
  }, [])
  console.log(quizArray)


  return (
    <div className="App">

    </div>
  );
}

export default App;

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!