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

80
Vistas
How to loop over response object with nested array

This is my response. that i am getting

{status: 'Success', length: 7, data: {…}}

This is an expanded version.

data:
tours: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
[[Prototype]]: Object
length: 7
status: "Success"

I wanted to loop over the tour property but doing a map is not going to work. I tried doing Object.entries() to convert it into an array but it is also not working. Can anyone suggest me a solution?

export const getData = () => {
  return async (dispatch) => {
    try {
      dispatch(isLoading(true));
      const res = await fetch(`http://localhost:5555/api/bc1/tours`);

      if (!res.ok) {
        throw new Error(`Error while connecting with server`);
      }

      const data = await res.json();
      dispatch(isLoading(false));
      dispatch(getTours(data));
    } catch (error) {
      dispatch(
        checkStatus({
          title: `Error`,
          message: error.message,
        })
      );
    }
  };
};

getTours is an empty array.

calling it in app.js

const dispatch = useDispatch();
  useEffect(() => {
    dispatch(getData());
  }, [dispatch]);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

No need to convert tours to object. You can do this:

const result = {status: 'Success', length: 7, data: {…}};
result.data.tours.map(function(item, i){
  // your code
})
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