Skip to content

Instantly share code, notes, and snippets.

@outsideris
Created July 6, 2011 07:54
Show Gist options
  • Save outsideris/1066777 to your computer and use it in GitHub Desktop.
Save outsideris/1066777 to your computer and use it in GitHub Desktop.
javascript foreach break
var params = qs.parse(url.parse(req.url).query)
, id = params.id
, BreakException = {};
try {
tweets.forEach(function(element, index) {
if(element.id == id) {
res.send({tweets:tweets.slice(index+1, index+21)});
throw BreakException;
}
});
} catch (e) {
if (e !== BreakException) throw e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment