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

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

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