{"id":13385,"date":"2021-05-01T21:11:01","date_gmt":"2021-05-01T12:11:01","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=13385"},"modified":"2023-05-27T20:54:06","modified_gmt":"2023-05-27T11:54:06","slug":"%e3%80%90javascript%e3%80%91%e9%85%8d%e5%88%97%e3%81%ae%e3%83%a1%e3%82%bd%e3%83%83%e3%83%89%e3%81%ae%e4%bd%bf%e3%81%84%e5%88%86%e3%81%91","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=13385","title":{"rendered":"\u3010JavaScript\u3011for\u6587\u3001\u7e70\u308a\u8fd4\u3057\u6587\u3001\u914d\u5217\u7cfb\u30e1\u30bd\u30c3\u30c9\u306e\u4f7f\u3044\u5206\u3051"},"content":{"rendered":"<h2>for(;;)<\/h2>\n<ul>\n<li>\u6614\u304b\u3089\u3042\u308b\u30eb\u30fc\u30d7\u6587<\/li>\n<li>eslint\u306b\u3082\u6012\u3089\u308c\u306a\u3044\u3002<\/li>\n<li>break\u3084continue\u3082\u4f7f\u3048\u308b\u3002<\/li>\n<\/ul>\n<h2>filter<\/h2>\n<h3>\u7279\u5fb4<\/h3>\n<p>break\u304c\u4f7f\u3048\u306a\u3044\u306e\u3067\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u8a08\u7b97\u91cf\u304c\u5897\u3048\u308b\u3002<\/p>\n<h2>find<\/h2>\n<h3>\u7279\u5fb4<\/h3>\n<h2>map<\/h2>\n<h3>\u7279\u5fb4<\/h3>\n<p>break\u304c\u4f7f\u3048\u306a\u3044\u306e\u3067\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u8a08\u7b97\u91cf\u304c\u5897\u3048\u308b\u3002<\/p>\n<h2>reduce<\/h2>\n<h3>\u7279\u5fb4<\/h3>\n<p>break\u304c\u4f7f\u3048\u306a\u3044\u306e\u3067\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u8a08\u7b97\u91cf\u304c\u5897\u3048\u308b\u3002<\/p>\n<h2>forEach<\/h2>\n<h3>\u7279\u5fb4<\/h3>\n<ul>\n<li>forEach\u306e\u5f15\u6570\u306f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3067\u3042\u308a\u5fc5\u305a\u914d\u5217\u306e\u5168\u8981\u7d20\u306b\u5bfe\u3057\u3066\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u304c\u547c\u3073\u51fa\u3055\u308c\u307e\u3059\u3002<\/li>\n<li>forEach\u306e\u5f15\u6570\u306f\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u306a\u306e\u3067\u3001for\u3084for in\u3001for of\u306e\u3088\u3046\u306bbreak\u3084continue\u306f\u3067\u304d\u306a\u3044\u3002(continue\u306e\u4ee3\u7528\u3068\u3057\u3066\u306freturn\u3092\u4f7f\u3048\u307e\u3059\u3002break\u306e\u4ee3\u7528\u306f\u306a\u3044\u306e\u3067\u8a08\u7b97\u91cf\u304c\u5897\u3048\u308b\u3002)<\/li>\n<\/ul>\n<h3>\u7528\u9014<\/h3>\n<h4>filter\u3001find\u3001map\u3001reduce\u3067\u3069\u3046\u306b\u3082\u306a\u3089\u306a\u3044\u5834\u5408\u306b\u4f7f\u3046\u3002<\/h4>\n<p>\u7406\u7531\u306f\u4ee5\u4e0b\u306e2\u70b9<\/p>\n<ul>\n<li>filter\u3084find\u306e\u65b9\u304c\u30b3\u30fc\u30c9\u306e\u610f\u56f3\u304c\u4f1d\u308f\u308a\u3084\u3059\u3044\u305f\u3081\u3002<\/li>\n<li>\u30b3\u30fc\u30c9\u304c\u77ed\u304f\u306a\u308b\u305f\u3081\u3002<\/li>\n<\/ul>\n<h4>forEach\u304c\u59a5\u5f53\u306a\u30b1\u30fc\u30b9<\/h4>\n<p>forEach\u3067\u56de\u3057\u3066\u3044\u308b\u914d\u5217\u81ea\u8eab\u306b\u5bfe\u3057\u3066\u306e\u307f\u4f5c\u7528\u3055\u305b\u308b\u30b1\u30fc\u30b9\u3002<\/p>\n<h2>for \u30ad\u30fc in \u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h2>\n<p>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30eb\u30fc\u30d7\u306e\u5834\u5408\u306b\u4f7f\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">const obj = { key1: 'val1', key2: 'val2', key3: 'val3' };\r\n\r\nfor (let key in obj) {\r\n  console.log(key + ' ' + obj[key]);\r\n}<\/pre>\n<p>\u4e00\u5fdc\u3001\u914d\u5217\u306e\u30eb\u30fc\u30d7\u306b\u3082\u4f7f\u7528\u3067\u304d\u307e\u3059\u304c\u3001\u5024\u3092\u53d6\u5f97\u3059\u308b\u306b\u306f\u3044\u3061\u3044\u3061\u300cobj[key]\u300d\u306a\u3069\u3068\u6307\u5b9a\u3057\u306a\u3051\u308c\u3070\u306a\u3089\u306a\u3044\u306e\u3067\u914d\u5217\u306e\u4f7f\u7528\u306b\u306f\u4e0d\u5411\u304d\u3067\u3059\u3002<\/p>\n<p>\u307e\u305f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u56de\u3059\u5834\u5408\u306b\u3082<span style=\"color: #ff0000;\"><strong>\u30d7\u30ed\u30c8\u30bf\u30a4\u30d7(__proto__)\u307e\u3067\u53d6\u5f97\u3067\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u306e\u3067\u57fa\u672c\u306f\u4f7f\u308f\u306a\u3044\u65b9\u304c\u826f\u3044<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<p>for of \u3068Object.keys\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u30eb\u30fc\u30d7\u3055\u305b\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2>for\/of\u30eb\u30fc\u30d7(ECMA2015\u3088\u308a)<\/h2>\n<h3>Airbnb \u306e\u300cJavaScript Style Guide\u300d\u3067\u306f\u4f7f\u308f\u306a\u3044\u3088\u3046\u306b\u8b66\u544a\u304c\u51fa\u307e\u3059\u3002<\/h3>\n<p>babel\u3067\u5909\u63db\u5f8c\u306e\u30b3\u30fc\u30c9\u306f\u300cregenerator-runtime\u300d\u304c\u5fc5\u8981\u306b\u306a\u308a\u30b3\u30fc\u30c9\u91cf\u304c\u81a8\u5927\u306b\u306a\u308b\u306e\u3067\u3067\u304d\u308b\u3060\u3051map\u3084forEach\u306a\u3069\u306e\u76ee\u7684\u306b\u3042\u3063\u305f\u69cb\u6587\u3092\u4f7f\u3046\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u3066\u3044\u308b\u3002<\/p>\n<p>for\/of\u30eb\u30fc\u30d7\u3092\u4f7f\u7528\u3059\u308b\u4e8b\u3067<span style=\"color: #ff0000;\"><strong>\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u3092\u4fdd\u6301\u3057\u3066\u3044\u308b\u5909\u6570\u304b\u3089\u30ad\u30fc\u3068\u5024\u3092\u9806\u756a\u306b\u53d6\u308a\u51fa\u3059\u4e8b\u304c\u53ef\u80fd<\/strong><\/span>\u306b\u306a\u308a\u307e\u3059\u3002\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u306b\u3064\u3044\u3066\u306f\u4e0b\u8a18\u306e\u8a18\u4e8b\u3092\u3054\u78ba\u8a8d\u304f\u3060\u3055\u3044\u3002<\/p>\n<blockquote class=\"wp-embedded-content\" data-secret=\"1mJUclmgMt\"><p><a href=\"http:\/\/www.code-magagine.com\/?p=10233\">\u3010JavaScript\u3011\u300c\u30b7\u30f3\u30dc\u30eb\u300d\u3001\u300c\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u300d\u3001\u300c\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u300d\u306b\u3064\u3044\u3066<\/a><\/p><\/blockquote>\n<p><iframe class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" src=\"http:\/\/www.code-magagine.com\/?p=10233&#038;embed=true#?secret=1mJUclmgMt\" data-secret=\"1mJUclmgMt\" width=\"500\" height=\"282\" title=\"&#8220;\u3010JavaScript\u3011\u300c\u30b7\u30f3\u30dc\u30eb\u300d\u3001\u300c\u30a4\u30c6\u30ec\u30fc\u30bf\u30fc\u300d\u3001\u300c\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u300d\u306b\u3064\u3044\u3066&#8221; &#8212; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30de\u30ac\u30b8\u30f3\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe><\/p>\n<h3>\u300c\u30d0\u30ea\u30e5\u30fc\u300d\u306e\u307f\u6271\u3046\u3002<\/h3>\n<p>ECMA2015\u3088\u308a\u914d\u5217\u306e\u4e2d\u306e\u5024\u306e\u5217\u6319\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3057\u305f\u3002<span style=\"color: #ff0000;\"><strong>\u666e\u901a\u306b\u914d\u5217\u306e\u5909\u6570\u306e\u307f\u6307\u5b9a\u3059\u308b\u3068\u30d0\u30ea\u30e5\u30fc\u306e\u307f\u3092\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u53ef\u80fd<\/strong><\/span>\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">let array = [10, 20, 30];\r\nfor (num of array) {\r\n  console.log(num); \/\/10,20,30\r\n}<\/pre>\n<h3>\u30eb\u30fc\u30d7\u306e\u300c\u30ad\u30fc\u300d\u3084\u300c\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u300d\u3092\u53d6\u5f97\u3059\u308b\u3002<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>keys\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3092\u5408\u308f\u305b\u3066\u4f7f\u3046\u4e8b\u3067\u30eb\u30fc\u30d7\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u6570\u3092\u5408\u308f\u305b\u3066\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">let array = [10, 20, 30];\r\nfor (num of array.keys()) {\r\n  console.log(num); \/\/0,1,2\r\n}<\/pre>\n<h3>\u300c\u30ad\u30fc\u300d\u3068\u300c\u30d0\u30ea\u30e5\u30fc\u300d\u306e\u3069\u3061\u3089\u3082\u53d6\u5f97\u3059\u308b\u3002<\/h3>\n<p><span style=\"color: #ff0000;\"><strong>entries\u30e1\u30bd\u30c3\u30c9<\/strong><\/span>\u3092\u4f7f\u3046\u3068\u30eb\u30fc\u30d7\u306e\u30ad\u30fc\u3068\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3069\u3061\u3089\u3082\u53d6\u5f97\u3059\u308b\u4e8b\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true  \">let array = [10, 20, 30];\r\nfor (num of array.entries()) {\r\n  console.log(num); \/\/[0,10]\u3001[0,20]\u3001[0,30]\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"for(;;) \u6614\u304b\u3089\u3042\u308b\u30eb\u30fc\u30d7\u6587 eslint\u306b\u3082\u6012\u3089\u308c\u306a\u3044\u3002 break\u3084continue\u3082\u4f7f\u3048\u308b\u3002 filter \u7279\u5fb4 break\u304c\u4f7f\u3048\u306a\u3044\u306e\u3067\u5834\u5408\u306b\u3088\u3063\u3066\u306f\u8a08\u7b97\u91cf\u304c\u5897\u3048\u308b\u3002 find \u7279\u5fb4 map \u7279\u5fb4 brea [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13385"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13385"}],"version-history":[{"count":9,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13385\/revisions"}],"predecessor-version":[{"id":20276,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/13385\/revisions\/20276"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13385"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}