Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8401305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:46:18+00:00 2026-06-09T21:46:18+00:00

More help, different issue. I want to return allLessonsArray from the inner loops, but

  • 0

More help, different issue. I want to return allLessonsArray from the inner loops, but for some reason it doesn’t reach outside the loop function. I’ve noted where it works, and where it doesn’t work. How do I return this to the outside?

var allLessonsArray= new Array();
$.each(lessonInTopicSectionArray, function(index, lesson){       
    var lastAttempt = 0;
    url='domain/learn/mod/lesson/report.php?id='+lesson.id+'&action=reportdetail&userid='+userid+'&try='+lastAttempt;
    $.get(url, function(data) {
        var lessonArray= new Array();
        $(data).find('tr.r1.lastrow td.cell.c0')
        .each(function(index, content) {
            var string=jQuery(content).html()
            score=parseInt(string.substr(string.length - 1));
            lessonArray[index]=score;   
        }); 
        allLessonsArray[index]={name:lesson.name, score: lessonArray};
        //This works.
        alert(allLessonsArray[0].name);
        alert(allLessonsArray[0].score[0]);     
    });
    //This doesn't work.
    alert(allLessonsArray[0].name);
    alert(allLessonsArray[0].score[0]);
});
return allLessonsArray;     
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:46:20+00:00Added an answer on June 9, 2026 at 9:46 pm

    $.get() is an AJAX ie. an asynchronous request, so you can’t do that as you want.

    You can do:

    var allLessonsArray= new Array();
    $.each(lessonInTopicSectionArray, function(index, lesson){       
        var lastAttempt = 0;
        url='http://www.training-source.org/learn/mod/lesson/report.php?id='+lesson.id+'&action=reportdetail&userid='+userid+'&try='+lastAttempt;
        $.get(url, function(data) {
            var lessonArray= new Array();
            $(data).find('tr.r1.lastrow td.cell.c0')
            .each(function(index, content) {
                var string=jQuery(content).html()
                score=parseInt(string.substr(string.length - 1));
                lessonArray[index]=score;   
            }); 
            allLessonsArray[index]={name:lesson.name, score: lessonArray};
    
             // check length to ensure that full array will return
            if( allLessonsArray.length === lessonInTopicSectionArray.length )
               reciever(allLessonsArray);
    
        });
    });
    
    function receiver(allLessonsArray){
      console.log(allLessonsArray);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Morning again..., Sorry to bother everyone but I need more help... I haven't done
I need some help with overlaying views using the prism framework.Its a little more
I found something about this issue for ASP, but it didn't help me much
I'm not a beginner, but the more I think about this issue, the more
Not really a coding question more a little help with my idea of a
please help me to identify which of these following is more optimized code? for(int
I have recently found myself becoming more negative about EF and cannot help wondering
This is more of an assignment work. I'm trying to help a friend debugging
I haven't been able to get any more console output (to help with debugging)
I was given some great help by redsquare to get this far to change

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.