0

i'm trying to get the number of table line using javascript. i'm using php api with javascript. from the php side evry thing is good and i get the lines number with the javascript function below. the problem that's i want to use this variable outside this function .

note : inside function is working

      const readNumberListe = async () => {
        const data = await fetch("action.php?readNumberListe=1", {
          method: "GET",
        });
        const response = await data.json();// the response is 5 for exepmle 
        var number = response.number_parent ; 
        console.log(number) ; // i get 5 in the console 
    
      };
      readNumberListe();

// but i want to use or print 'number' here
  • 5
    Just `return` it, then `await readNumberListe()`? – Bergi May 05 '22 at 21:56
  • What you're asking isn't possible, you should read up on scoping - "https://stackoverflow.com/questions/500431/what-is-the-scope-of-variables-in-javascript" As @Bergi said, you can change this code to `return` the variable and assign the result of the function to a variable in that scope. – undefined May 05 '22 at 21:58

0 Answers0