{"id":856,"date":"2025-08-05T16:42:42","date_gmt":"2025-08-05T07:42:42","guid":{"rendered":"https:\/\/nexive.tech\/?p=856"},"modified":"2025-08-05T16:42:42","modified_gmt":"2025-08-05T07:42:42","slug":"%e3%80%90%e3%82%b5%e3%82%af%e3%83%83%e3%81%a8%e8%a7%a3%e8%aa%ac%e3%80%91javascript-for%e3%83%bbwhile%e3%83%bbfor-of%e3%83%bbfor-in%e3%81%ae%e9%81%95%e3%81%84%e3%81%a8%e4%bd%bf%e3%81%84%e5%88%86","status":"publish","type":"post","link":"https:\/\/nexive.tech\/?p=856","title":{"rendered":"\u3010\u30b5\u30af\u30c3\u3068\u89e3\u8aac\u3011JavaScript for\u30fbwhile\u30fbfor&#8230;of\u30fbfor&#8230;in\u306e\u9055\u3044\u3068\u4f7f\u3044\u5206\u3051"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>JavaScript\u306b\u304a\u3051\u308b\u4ee3\u8868\u7684\u306a\u7e70\u308a\u8fd4\u3057\u69cb\u6587\u306e\u9055\u3044\u3068\u7528\u9014\u3092\u6574\u7406<\/li>\n\n\n\n<li>for \/ while \/ for&#8230;of \/ for&#8230;in \u306e\u4f7f\u3044\u5206\u3051\u6307\u91dd\u3092\u660e\u793a<\/li>\n\n\n\n<li>\u5b9f\u884c\u53ef\u80fd\u306a\u30b3\u30fc\u30c9\u4ed8\u304d\u3067\u69cb\u6587\u3054\u3068\u306e\u7279\u5fb4\u3092\u6bd4\u8f03<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">2. JavaScript\u306e\u7e70\u308a\u8fd4\u3057\u69cb\u6587\u3068\u306f\uff1f<\/h2>\n\n\n\n<p>JavaScript\u3067\u306f\u3001\u7e70\u308a\u8fd4\u3057\u51e6\u7406\uff08\u30eb\u30fc\u30d7\uff09\u3092\u8a18\u8ff0\u3059\u308b\u69cb\u6587\u3068\u3057\u3066\u8907\u6570\u306e\u9078\u629e\u80a2\u304c\u3042\u308a\u307e\u3059\u3002\u4e3b\u306a\u3082\u306e\u306b\u3001<code>for<\/code>\u6587\u3001<code>while<\/code>\u6587\u3001<code>for...of<\/code>\u6587\u3001<code>for...in<\/code>\u6587\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u308c\u3089\u306f\u3059\u3079\u3066\u300c\u53cd\u5fa9\u51e6\u7406\u300d\u3092\u76ee\u7684\u3068\u3057\u305f\u69cb\u6587\u3067\u3059\u304c\u3001\u5bfe\u8c61\u3068\u3059\u308b\u30c7\u30fc\u30bf\u69cb\u9020\u3084\u30eb\u30fc\u30d7\u306e\u5236\u5fa1\u65b9\u6cd5\u3001\u51e6\u7406\u52b9\u7387\u306b\u9055\u3044\u304c\u3042\u308b\u305f\u3081\u3001\u9069\u5207\u306a\u4f7f\u3044\u5206\u3051\u304c\u91cd\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u305f\u3068\u3048\u3070\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u6307\u5b9a\u304c\u5fc5\u8981\u306a\u5834\u5408\u306f<code>for<\/code>\u3001\u914d\u5217\u8981\u7d20\u306e\u9806\u6b21\u51e6\u7406\u306b\u306f<code>for...of<\/code>\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u5217\u6319\u306b\u306f<code>for...in<\/code>\u304c\u5411\u3044\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001\u305d\u308c\u305e\u308c\u306e\u69cb\u6587\u306e\u6319\u52d5\u3068\u4ee3\u8868\u7684\u306a\u7528\u9014\u3092\u6bd4\u8f03\u3057\u306a\u304c\u3089\u3001\u5b9f\u52d9\u306b\u304a\u3051\u308b\u4f7f\u3044\u5206\u3051\u306e\u6307\u91dd\u3092\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. \u8a73\u7d30\u89e3\u8aac<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u30d9\u30fc\u30b9\u3067\u30eb\u30fc\u30d7\uff1a<code>for<\/code>\u6587<\/h3>\n\n\n\n<p><code>for<\/code>\u6587\u306f\u3001\u6307\u5b9a\u3057\u305f\u56de\u6570\u3060\u3051\u30eb\u30fc\u30d7\u51e6\u7406\u3092\u884c\u3046\u57fa\u672c\u7684\u306a\u69cb\u6587\u3067\u3059\u3002\u30ab\u30a6\u30f3\u30bf\u5909\u6570\u3092\u4f7f\u3063\u3066\u3001\u6dfb\u5b57\u3092\u660e\u793a\u7684\u306b\u64cd\u4f5c\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u914d\u5217\u306e\u8981\u7d20\u3092\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u6307\u5b9a\u3067\u51e6\u7406\nconst items = &#91;'apple', 'banana', 'orange'&#93;;\nfor (let i = 0; i &lt; items.length; i++) {\n  console.log(i + ': ' + items&#91;i&#93;);\n}\n\/\/ \u51fa\u529b: 0: apple, 1: banana, 2: orange\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u914d\u5217\u306e\u8981\u7d20\u3092\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u6307\u5b9a\u3067\u51e6\u7406<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">const<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4FC1FF\">items<\/span><span style=\"color: #D4D4D4\"> = &#91;<\/span><span style=\"color: #CE9178\">&#39;apple&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;banana&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;orange&#39;<\/span><span style=\"color: #D4D4D4\">&#93;;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #569CD6\">let<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #B5CEA8\">0<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> &lt; <\/span><span style=\"color: #9CDCFE\">items<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #9CDCFE\">length<\/span><span style=\"color: #D4D4D4\">; <\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\">++) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #CE9178\">&#39;: &#39;<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #9CDCFE\">items<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #9CDCFE\">i<\/span><span style=\"color: #D4D4D4\">&#93;);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: 0: apple, 1: banana, 2: orange<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6761\u4ef6\u5f0f\u3068\u5897\u6e1b\u51e6\u7406\u3092\u67d4\u8edf\u306b\u8a2d\u5b9a\u53ef\u80fd<\/li>\n\n\n\n<li>\u6dfb\u5b57\u304c\u5fc5\u8981\u306a\u5834\u5408\u3084\u9006\u9806\u51e6\u7406\u306b\u3082\u9069\u3057\u3066\u3044\u308b<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u6761\u4ef6\u3092\u6e80\u305f\u3059\u9650\u308a\u7e70\u308a\u8fd4\u3059\uff1a<code>while<\/code>\u6587<\/h3>\n\n\n\n<p><code>while<\/code>\u6587\u306f\u3001\u6761\u4ef6\u304c\u771f\u3067\u3042\u308b\u9650\u308a\u7e70\u308a\u8fd4\u3057\u307e\u3059\u3002\u56de\u6570\u304c\u6c7a\u307e\u3063\u3066\u3044\u306a\u3044\u51e6\u7406\u306b\u9069\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5024\u304c3\u306b\u306a\u308b\u307e\u3067\u7e70\u308a\u8fd4\u3059\nlet num;\ndo {\n  num = Math.floor(Math.random() * 5);\n  console.log('\u8a66\u884c:', num);\n} while (num !== 3);\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30e9\u30f3\u30c0\u30e0\u306a\u6570\u5024\u304c3\u306b\u306a\u308b\u307e\u3067\u7e70\u308a\u8fd4\u3059<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">let<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">num<\/span><span style=\"color: #D4D4D4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">do<\/span><span style=\"color: #D4D4D4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">num<\/span><span style=\"color: #D4D4D4\"> = <\/span><span style=\"color: #9CDCFE\">Math<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">floor<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">Math<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">random<\/span><span style=\"color: #D4D4D4\">() * <\/span><span style=\"color: #B5CEA8\">5<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #CE9178\">&#39;\u8a66\u884c:&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">num<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">} <\/span><span style=\"color: #C586C0\">while<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #9CDCFE\">num<\/span><span style=\"color: #D4D4D4\"> !== <\/span><span style=\"color: #B5CEA8\">3<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9f\u884c\u6761\u4ef6\u306b\u5fdc\u3058\u3066\u52d5\u7684\u306b\u7e70\u308a\u8fd4\u3059\u51e6\u7406\u306b\u9069\u3057\u3066\u3044\u308b<\/li>\n\n\n\n<li>\u6761\u4ef6\u3092\u6e80\u305f\u3055\u306a\u3051\u308c\u3070\u4e00\u5ea6\u3082\u5b9f\u884c\u3055\u308c\u306a\u3044\uff08do&#8230;while\u3092\u9664\u304f\uff09<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u914d\u5217\u306a\u3069\u53cd\u5fa9\u53ef\u80fd\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\uff1a<code>for...of<\/code>\u6587<\/h3>\n\n\n\n<p><code>for...of<\/code>\u6587\u306f\u3001\u53cd\u5fa9\u53ef\u80fd\uff08iterable\uff09\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08\u4f8b\uff1a\u914d\u5217\u3001\u6587\u5b57\u5217\u3001Set\u306a\u3069\uff09\u306b\u5bfe\u3057\u3066\u9806\u6b21\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u914d\u5217\u8981\u7d20\u306e\u5185\u5bb9\u30921\u3064\u305a\u3064\u51fa\u529b\nconst colors = &#91;'red', 'green', 'blue'&#93;;\nfor (const color of colors) {\n  console.log(color);\n}\n\/\/ \u51fa\u529b: red, green, blue\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u914d\u5217\u8981\u7d20\u306e\u5185\u5bb9\u30921\u3064\u305a\u3064\u51fa\u529b<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">const<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4FC1FF\">colors<\/span><span style=\"color: #D4D4D4\"> = &#91;<\/span><span style=\"color: #CE9178\">&#39;red&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;green&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #CE9178\">&#39;blue&#39;<\/span><span style=\"color: #D4D4D4\">&#93;;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #569CD6\">const<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4FC1FF\">color<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">of<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">colors<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">color<\/span><span style=\"color: #D4D4D4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: red, green, blue<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u64cd\u4f5c\u304c\u4e0d\u8981\u306a\u5834\u5408\u306b\u7c21\u6f54<\/li>\n\n\n\n<li>\u914d\u5217\u3084Set\u306a\u3069\u3001\u9806\u5e8f\u3092\u4fdd\u3063\u305f\u30c7\u30fc\u30bf\u306e\u51e6\u7406\u306b\u6709\u7528<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ad\u30fc\u5217\u6319\u306b\uff1a<code>for...in<\/code>\u6587<\/h3>\n\n\n\n<p><code>for...in<\/code>\u6587\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5217\u6319\u53ef\u80fd\u306a\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\uff08\u30ad\u30fc\uff09\u306b\u5bfe\u3057\u3066\u30eb\u30fc\u30d7\u51e6\u7406\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e\"><span style=\"background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e\">JavaScript<\/span><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#D4D4D4;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>\/\/ \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u5024\u3092\u5217\u6319\nconst user = { name: 'Taro', age: 30 };\nfor (const key in user) {\n  console.log(key + ': ' + user&#91;key&#93;);\n}\n\/\/ \u51fa\u529b: name: Taro, age: 30\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki dark-plus\" style=\"background-color: #1E1E1E\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3068\u5024\u3092\u5217\u6319<\/span><\/span>\n<span class=\"line\"><span style=\"color: #569CD6\">const<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4FC1FF\">user<\/span><span style=\"color: #D4D4D4\"> = { <\/span><span style=\"color: #9CDCFE\">name:<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #CE9178\">&#39;Taro&#39;<\/span><span style=\"color: #D4D4D4\">, <\/span><span style=\"color: #9CDCFE\">age:<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #B5CEA8\">30<\/span><span style=\"color: #D4D4D4\"> };<\/span><\/span>\n<span class=\"line\"><span style=\"color: #C586C0\">for<\/span><span style=\"color: #D4D4D4\"> (<\/span><span style=\"color: #569CD6\">const<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #4FC1FF\">key<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #569CD6\">in<\/span><span style=\"color: #D4D4D4\"> <\/span><span style=\"color: #9CDCFE\">user<\/span><span style=\"color: #D4D4D4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">  <\/span><span style=\"color: #9CDCFE\">console<\/span><span style=\"color: #D4D4D4\">.<\/span><span style=\"color: #DCDCAA\">log<\/span><span style=\"color: #D4D4D4\">(<\/span><span style=\"color: #9CDCFE\">key<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #CE9178\">&#39;: &#39;<\/span><span style=\"color: #D4D4D4\"> + <\/span><span style=\"color: #9CDCFE\">user<\/span><span style=\"color: #D4D4D4\">&#91;<\/span><span style=\"color: #9CDCFE\">key<\/span><span style=\"color: #D4D4D4\">&#93;);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #D4D4D4\">}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #6A9955\">\/\/ \u51fa\u529b: name: Taro, age: 30<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u914d\u5217\u306b\u5bfe\u3057\u3066\u4f7f\u3046\u3068\u9806\u5e8f\u304c\u4fdd\u8a3c\u3055\u308c\u305a\u6ce8\u610f\u304c\u5fc5\u8981<\/li>\n\n\n\n<li><code>hasOwnProperty<\/code>\u3067\u7d99\u627f\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u9664\u5916\u3059\u308b\u3053\u3068\u304c\u63a8\u5968<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">4. \u3088\u304f\u3042\u308b\u30df\u30b9\u30fb\u8aa4\u89e3\u30fb\u843d\u3068\u3057\u7a74<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>for...in<\/code>\u306f\u914d\u5217\u306e\u53cd\u5fa9\u306b<strong>\u4e0d\u5411\u304d<\/strong>\u3067\u3059\u3002\u6570\u5024\u9806\u304c\u4fdd\u8a3c\u3055\u308c\u306a\u3044\u305f\u3081\u3001\u610f\u56f3\u3057\u306a\u3044\u9806\u5e8f\u306b\u306a\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>for...of<\/code>\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\uff08plain object\uff09\u306b\u306f\u4f7f\u3048\u307e\u305b\u3093\u3002\u30a8\u30e9\u30fc\u306b\u306a\u308b\u304b\u3001<code>TypeError<\/code>\u304c\u767a\u751f\u3057\u307e\u3059\u3002<\/li>\n\n\n\n<li><code>while<\/code>\u30eb\u30fc\u30d7\u306f\u3001\u6761\u4ef6\u304c\u5e38\u306b\u771f\u3060\u3068\u7121\u9650\u30eb\u30fc\u30d7\u306b\u306a\u308a\u307e\u3059\u3002\u7d42\u4e86\u6761\u4ef6\u3092\u660e\u793a\u3059\u308b\u3053\u3068\u304c\u91cd\u8981\u3067\u3059\u3002<\/li>\n\n\n\n<li>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5217\u6319\u3059\u308b\u5834\u5408\u3001<code>for...in<\/code>\u306f\u7d99\u627f\u30d7\u30ed\u30d1\u30c6\u30a3\u3082\u542b\u3080\u305f\u3081\u3001<code>Object.hasOwn()<\/code>\u307e\u305f\u306f<code>Object.prototype.hasOwnProperty.call()<\/code>\u3068\u7d44\u307f\u5408\u308f\u305b\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">5. \u307e\u3068\u3081<\/h2>\n\n\n\n<p>JavaScript\u306e\u30eb\u30fc\u30d7\u69cb\u6587\u306f\u7528\u9014\u306b\u3088\u3063\u3066\u4f7f\u3044\u5206\u3051\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>for<\/code>: \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u304c\u5fc5\u8981\u306a\u914d\u5217\u64cd\u4f5c\u3084\u30ab\u30a6\u30f3\u30c8\u51e6\u7406\u306b\u6700\u9069<\/li>\n\n\n\n<li><code>while<\/code>: \u56de\u6570\u4e0d\u5b9a\u306e\u6761\u4ef6\u4ed8\u304d\u30eb\u30fc\u30d7\u306b\u9069\u3059\u308b<\/li>\n\n\n\n<li><code>for...of<\/code>: \u914d\u5217\u3084Set\u306a\u3069\u306e\u8981\u7d20\u9806\u51e6\u7406\u306b\u4f7f\u3044\u3084\u3059\u3044<\/li>\n\n\n\n<li><code>for...in<\/code>: \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ad\u30fc\u5217\u6319\u304c\u76ee\u7684<\/li>\n<\/ul>\n\n\n\n<p>\u69cb\u6587\u306e\u9055\u3044\u3084\u4ed5\u69d8\u4e0a\u306e\u5236\u7d04\u3092\u7406\u89e3\u3057\u3001\u9069\u5207\u306a\u30eb\u30fc\u30d7\u3092\u9078\u629e\u3059\u308b\u3053\u3068\u304c\u3001\u4fdd\u5b88\u6027\u3084\u610f\u56f3\u306e\u660e\u78ba\u3055\u306b\u3064\u306a\u304c\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u672c\u8a18\u4e8b\u306e\u30dd\u30a4\u30f3\u30c8 2. JavaScript\u306e\u7e70\u308a\u8fd4\u3057\u69cb\u6587\u3068\u306f\uff1f JavaScript\u3067\u306f\u3001\u7e70\u308a\u8fd4\u3057\u51e6\u7406\uff08\u30eb\u30fc\u30d7\uff09\u3092\u8a18\u8ff0\u3059\u308b\u69cb\u6587\u3068\u3057\u3066\u8907\u6570\u306e\u9078\u629e\u80a2\u304c\u3042\u308a\u307e\u3059\u3002\u4e3b\u306a\u3082\u306e\u306b\u3001for\u6587\u3001while\u6587\u3001for&#8230;of\u6587\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":934,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","footnotes":""},"categories":[86],"tags":[],"class_list":["post-856","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=856"}],"version-history":[{"count":2,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/856\/revisions"}],"predecessor-version":[{"id":935,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/posts\/856\/revisions\/935"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=\/wp\/v2\/media\/934"}],"wp:attachment":[{"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nexive.tech\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}