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

102
Vistas
How to iterate var in javascript. Array inside array

I'm trying to iterate over the result of an array, but it's not working. Each result can have up to 20 results. I'm getting it three times, but I can't iterate through each of the 60 results


     var responses = [];
     var url = "http://api.crossref.org/works?filter=prefix:10.5090,from-created-date:2020,until-created-date:2020";
   
    async function doAjax(args) {
    const result = await $.ajax({
        url: url,
        type: 'GET',
        data: args
    });

    return result;
    }
    
    const stuff = doAjax('cursor=*').then((data) => {
        responses.push(data.message.items);
        var totalresults = data.message['total-results'];
        var cursor = 'cursor='+data.message['next-cursor'];

        if (totalresults > 20) {
            for (var i = 1; i <= 2; i++) {
                var selector = '' + i;
                selector = 'responses' + selector;
                selector = data.message.items;

                $.when(doAjax(cursor)).done(function(selector){
                    responses.push(selector.message.items);
                })
            }
        }
        console.log(responses);
        $.each(responses, function(index,value){
            console.log(value.DOI); // this line returns undefined
        })
    });

enter image description here

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Since responses is an array of arrays you'll have to also iterate each sub-array before you can access the individual properties of its elements.

Also there is no need to use $.each. You can just use array.forEach:

// demo data
var responses = [
  [{DOI: 0}, {DOI: 1}, {DOI: 2}],
  [{DOI: 3}, {DOI: 4}, {DOI: 5}],
  [{DOI: 6}, {DOI: 7}, {DOI: 8}]
];

responses.forEach(function(array) {
  array.forEach(function(value) {
    console.log(value.DOI);
  });
});

about 4 years ago · Santiago Trujillo 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