I am looking for a way to stop a loop with a click event(sort of panic button). If you click the button it should stop immediately.
// basic idea
$.each(someArray, function(index, value){
setTimeout(function(){
console.log(index);
},5000*index);
});
$('#panic-button').click(function(){
//the code that should stop the looping
}):