'$.get() has not been answered yet, how to get the information to a var [duplicate]

I guess I don't know how to say this properly, but I have been searching for hours and I can't seem to get an answer to this. I am trying to get the name of the world out of the .get call. However all the ways I go about it fail and these are all the ways I have seen. Most answers are over 8 year ago. I thought if I i just homeworld = world.name that would work, but it don't if I am trying to bring it out of the second get call. They become undefine, so I was like how do you use the data section {Homeworld: homeworld} but I believe that makes it a different variable so is there anyway i can do this?

$(document).ready(function () {
  var homeworld;
  var i;
  for (i = 1; i <= 10; i++) {
    $.get("https://swapi.dev/api/people/" + i, function (people) {
      
      //trying to get the homeworld out of this call to make life easier
      //people.homeworld is a url  
      $.get(people.homeworld,{Homeworld:homeworld}, function (world) {
        Homeworld =world.name;        
       });

      // console.log(homeworld);
      var displayData = `
          <div>
            <h1>${people.name}</h1>
            <h1>${homeworld}</h1>
          </div>
          `;
      $("#people").append(displayData);
    });
  }
});

I additionally tried to make a variable like

var hw = $.get(people.homeworld, function (world) {
        return world.name;        
       });


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source