I want to iteratate through my result array. But even when I am pushing only numbers to the array the length function is not working on this. In the webbrowser I clearly see that the array is created. But when I want to use the lengh-function it only shows 0.
let array = [];
fetch('./api/getFromDatabase', {
    method: "POST",
    headers: {
      "Content-Type": "application/json"
    },
  }).then(response => response.json())
  .then(data => {
    data.forEach(tocken => {
      array.push(3);
    })
  })
  .catch(err => alert(err))
console.log(array);
console.log(array.length); //not working
let array1 = [3, 4, 2];
console.log(array1);
console.log(array1.length); //working

 
    