Skip to content

Instantly share code, notes, and snippets.

@ondrek
Last active December 22, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ondrek/6420665 to your computer and use it in GitHub Desktop.
Save ondrek/6420665 to your computer and use it in GitHub Desktop.
How to iterate array only to first wanted item and finish
function iterateArrayToFirstResult(arr){
loop: {
for (var i=0; i<arr.length; i++) {
if (arr[i]==42) {
console.log('You just found answer to the ultimate question of Life');
break loop;
}
console.log('Your array havent number 42');
}
}
}
iterateArrayToFirstResult([2,3,42,5,6]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment