Basically I have a function which loops through all the elements from an api and pushes it to a array and then I return the array, but I am getting random of amount of elements everytime I run this function.
function getElements() {
const url = "https://neelpatel05.pythonanywhere.com/element/atomicnumber?atomicnumber=";
var elements = [];
for(var i=1;i<=118;i++){
newurl = url+i.toString();
fetch(newurl)
.then(response => response.json())
.then(data => elements.push(data.symbol))
}
return elements;
}
console.log(getElements());
thanks in advance