0

I simplified the code, it would have been too long; I have three functions; the first contains the value, an array called multi, to be brought into the third; the second is only an intermediary

how do i bring multi into the third function?

function updateScegliFilm(film) {
  var url1 = "https://api.themovie.org/search/movie?api_key=" + key + "&query=" + film;
  var multi = [];
  fetch(url1)
    .then(response => response.json())
    .then(json => {
      var idFilmElenco = json['id'];
      var titleFilm = json['title'];
      output = new Array(idFilmElenco, titleFilm);
      multi.push(output);
      return multi;
    });
}

function gestioneElenco(output) {
  output.forEach(film => {
    tendina(film);
  });
}

function tendina(film, multi) {
  updateScegliFilm(film, multi);
  alert(multi);
}
Dave Newton
  • 158,873
  • 26
  • 254
  • 302
  • Please see [How do I return the response from an aynchronous call](https://stackoverflow.com/q/14220321/438992), which this duplicates. – Dave Newton Apr 21 '21 at 14:17
  • Unrelated, but `gestioneElenco` is just `output.forEach(tendina)` – Dave Newton Apr 21 '21 at 14:19
  • I have read some of the articles you have recommended to me; from my point of view the subject is very complicated; if someone showed me how to handle asynchronous functions on my code it would be ideal – Adrenerg1co Apr 24 '21 at 16:49
  • The dupe does, and there are many, many tutorials available. What specifically is the problem? – Dave Newton Apr 24 '21 at 19:40
  • I change the code so: function tendina(film, multi) { updateScegliFilm(film, multi) .then(multi=> { alert(multi); }); and thi is the result: Uncaught ReferenceError: multi is not defined – Adrenerg1co Apr 26 '21 at 18:20

0 Answers0