I have a function:
function check(id) {
let index = 0
fetch('https://ddragon.leagueoflegends.com/api/versions.json')
.then(e => e.json())
.then((res) =>res.forEach( element =>{
fetch('https://ddragon.leagueoflegends.com/cdn/'+element+'/img/profileicon/'+id+'.png')
.then(response => {
if(response.ok){
index++
}
else{
return index
}
})
}))
}
The code seems to be dirty and not right, sorry for that.
I am getting an array of numbers and at line 6, I check if the website is legit. After some index, invalid URLs will start. I want to break foreach loop when an invalid URL tried to fetch. I tried to convert 'foreach' loop to a 'some' loop and tried some try-catch blocks but I couldn't break the loop. If you want to see how it stacks when invalid URLs start to stack