Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

106
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda