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

104
Views
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 answers
Answer question

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