Skip to content

Instantly share code, notes, and snippets.

@ohnishiakira
Created June 20, 2011 06:21
Show Gist options
  • Save ohnishiakira/1035198 to your computer and use it in GitHub Desktop.
Save ohnishiakira/1035198 to your computer and use it in GitHub Desktop.
JavaScriptのfor文の書き方
var ary = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
// 普通の書き方
for (var i = 0; i < 10; i++) { console.log(ary[i]); }
// こう書くとループ内がシンプルになる。その分 for (...) の部分が長くなるけど。
for (var i = 0, a = 0; i < 10; i++, a = ary[i]) { console.log(a); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment