{"id":7724,"date":"2020-08-31T15:00:43","date_gmt":"2020-08-31T06:00:43","guid":{"rendered":"https:\/\/blog.capilano-fw.com\/?p=7724"},"modified":"2020-08-31T17:17:05","modified_gmt":"2020-08-31T08:17:05","slug":"javascript%e3%81%ae%e3%83%8f%e3%83%9e%e3%82%8a%e3%81%a9%e3%81%93%e3%82%8d%e5%85%a811%e4%bb%b6%ef%bc%81","status":"publish","type":"post","link":"https:\/\/blog.capilano-fw.com\/?p=7724","title":{"rendered":"JavaScript\u306e\u30cf\u30de\u308a\u3069\u3053\u308d\u516811\u4ef6\uff01"},"content":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u3054\u3068\u304d\u304c\u30fb\u30fb\u30fb\u3068\u3044\u3046\u304a\u8a71\u306a\u306e\u3067\u3059\u304c\u3001\u5b9f\u306f\u5c11\u3057\u524d\u304b\u3089\u500b\u4eba\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30aa\u30f3\u30e9\u30a4\u30f3\u30fb\u30ec\u30c3\u30b9\u30f3\u3092\u3084\u3089\u305b\u3066\u3082\u3089\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u5c11\u3057\u524d\u3042\u308b\u751f\u5f92\u3055\u3093\u304b\u3089\u300c<strong>JavaScript\u3067\u3053\u308c\u306f\u77e5\u3063\u3066\u304a\u3044\u305f\u65b9\u304c\u3044\u3044\u3088\u3001\u3068\u3044\u3046\u3082\u306e\u304c\u3042\u3063\u305f\u3089\u305c\u3072\u77e5\u308a\u305f\u3044<\/strong>\u300d\u3068\u3044\u3046\u3054\u8981\u671b\u3092\u3044\u305f\u3060\u304d\u3001\u79c1\u3082\u3044\u3044\u6a5f\u4f1a\u3060\u3068\u601d\u3044\u3001\u305d\u3046\u3044\u3063\u305f\u5185\u5bb9\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u305d\u306e\u4e2d\u3067\u3001\u3072\u3068\u3064\u3057\u307f\u3058\u307f\u3068\u611f\u3058\u305f\u3053\u3068\u304c\u3042\u3063\u305f\u306e\u3067\u3059\u304c\u3001<\/p>\n<p>\u305d\u308c\u306f\u30fb\u30fb\u30fb\u30fb\u30fb<\/p>\n<p><strong style=\"font-size: 35px;\">\u3088\u304f\u8003\u3048\u305f\u3089JavaScript\u3063\u3066\u30cf\u30de\u30ea\u3069\u3053\u308d\u591a\u3044\u3088\u306d\u30fb\u30fb\u30fb\ud83d\udca6<\/strong><\/p>\n<p>\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u7d1b\u3044\u306a\u308a\u306b\u308215\u5e74\u4ee5\u4e0a\u3001\u307b\u307c\u6bce\u65e5\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u66f8\u3044\u3066\u304d\u305f\u306e\u3067\u305d\u308c\u307b\u3069\u6c17\u306b\u306a\u3089\u306a\u304f\u306a\u3063\u3066\u3057\u307e\u3044\u307e\u3057\u305f\u304c\u3001\u3082\u3057\u4eca\u65e5\u304b\u3089<code>JavaScript<\/code>\u3092\u52c9\u5f37\u3059\u308b\u306a\u3089\u300c<strong>\u3044\u3084\u3044\u3084\u3001\u305d\u308c\u30c0\u30e1\u3067\u3057\u3087\u30fb\u30fb\u30fb\ud83d\ude02<\/strong>\u300d\u3068\u3044\u3046\u3088\u3046\u306a\u5185\u5bb9\u304c\u3042\u308b\u3053\u3068\u306b\u6c17\u304c\u3064\u3044\u305f\u3093\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3053\u3067\u2757<\/p>\n<p>\u4eca\u56de\u306f\u3001\u300c<strong>JavaScript\u306e\u30cf\u30de\u30ea\u3069\u3053\u308d<\/strong>\u300d\u3068\u3044\u3046\u30c6\u30fc\u30de\u3067\u5185\u5bb9\u3092\u307e\u3068\u3081\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<p>\u305c\u3072<code>JavaScript<\/code>\u5b66\u7fd2\u8005\u3055\u3093\u305f\u3061\u306b\u304a\u5f79\u306b\u7acb\u3066\u307e\u3057\u305f\u3089\u5b09\u3057\u3044\u3067\u3059\ud83d\ude0a\u2728<\/p>\n<p>\u203b \u3061\u306a\u307f\u306b\u3001\u3042\u304f\u307e\u3067\u79c1\u306e\u611f\u899a\u3067\u3059\u304c<strong>\u3010\u30cf\u30de\u30ea\u5ea6\u3011\u3068\u3057\u3066\uff11\u301c\uff15\u306e\u6570\u5b57\u3092\u5404\u9805\u76ee\u306b\u3064\u3051\u3066\u3044\u307e\u3059\u3002<\/strong><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4328 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3.png\" alt=\"\" width=\"364\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3.png 364w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/08\/no_3-300x264.png 300w\" sizes=\"auto, (max-width: 364px) 100vw, 364px\" \/>\u300c\u306f\u3058\u3081\u3066\u77e5\u3063\u305f\u3068\u304d\u306f\u3001\u3053\u3046\u306a\u308a\u307e\u3057\u305f\uff08\u7b11\uff09\ud83d\udc46\u300d<\/p>\n<p><strong>\u5b9f\u884c\u74b0\u5883\uff1a<\/strong> Google Chrome 84<\/p>\n<h1>Date() \u306e\u6708\u306f\u6570\u5b57\u304c\u30ba\u30ec\u308b<\/h1>\n<p><code>JavaScript<\/code>\u3067\u65e5\u4ed8\u306e\u64cd\u4f5c\u3092\u3059\u308b\u3068\u304d\u306b\u3088\u304f\u4f7f\u308f\u308c\u308b\u306e\u304c<code>Date()<\/code>\u3067\u3059\u3002<\/p>\n<p>\u305f\u3060\u3001\u3053\u306e<code>Date()<\/code>\u3067\u6708\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u306f<strong>\u30af\u30bb\u304c\u5f37\u3044\u306e\u3067\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3067\u306f\u3001\u4eca\u6708\u304c\u4f55\u6708\u306a\u306e\u304b\u3092\u53d6\u5f97\u3059\u308b\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>\/\/ \u26a0 \u3053\u308c\u306f\u9593\u9055\u3063\u305f\u4f8b\u3067\u3059<\/strong>\r\n\r\nconst dt = new Date(); \/\/ \u4eca\u6708\u304c\uff18\u6708\u3060\u3068\u3057\u3066\u3001\r\nconst month = dt.getMonth(); \/\/ \ud83d\udc48 <strong>\u3053\u3053\u306f\u300c7\u300d\u306b\u306a\u308b<\/strong>\ud83d\ude2b<\/pre>\n<p>\u305d\u3046\u3067\u3059\u3002<\/p>\n<p>\u5b9f\u306f<code>getMonth()<\/code>\u306f<strong>\u30bc\u30ed\u304b\u3089\u59cb\u307e\u308b\u6570\u5b57\u304c\u53d6\u5f97\u3055\u308c\u308b<\/strong>\u306e\u3067\u3001\u5b9f\u969b\u306e\u30c7\u30fc\u30bf\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\uff11\u6708 \u2192 0\uff08\u30bc\u30ed\uff09<br \/>\n<span style=\"font-size: 1rem;\">\uff12\u6708 \u2192 1<br \/>\n<\/span><span style=\"font-size: 1rem;\">\uff13\u6708 \u2192 2<br \/>\n&#8230;<br \/>\n<\/span><span style=\"font-size: 1rem;\">11\u6708 \u2192 10<br \/>\n12\u6708 \u2192 11<\/span><\/p>\n<p>\u304a\u305d\u3089\u304f\u82f1\u8a9e\u3067\u306f\u3001\u6708\u304c <code>January<\/code>, <code>February<\/code>, <code>March<\/code> &#8230; \u3068\u540d\u524d\u304c\u3064\u3044\u3066\u3044\u308b\u306e\u3067<strong>\u6570\u5b57\u3068\u3044\u3046\u3088\u308a\u306f\u4f55\u500b\u76ee\u307f\u305f\u3044\u306a\u30a4\u30e1\u30fc\u30b8\u306a\u306e\u3067\u3057\u3087\u3046\u3002<\/strong><\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u3053\u308c\u3092\u89e3\u6c7a\u3059\u308b\u306b\u306f\u3001\u6b21\u306e\u3088\u3046\u306b<code>+1<\/code>\u3092\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<pre>const dt = new Date();\r\nconst month = <strong>dt.getMonth() + 1;<\/strong> \/\/ \u3053\u308c\u3067\u4eca\u6708\u306e\u6570\u5b57\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059<\/pre>\n<p>\u3057\u304b\u3082\u3001\u65e5\u4ed8\u3092\u53d6\u5f97\u3059\u308b<code>getDate()<\/code>\u306f\u9006\u306b\uff11\u304b\u3089\u59cb\u307e\u308b\u306e\u3067\u3055\u3089\u306b\u6df7\u4e71\u3055\u305b\u3089\u308c\u307e\u3059\u306d\u30fb\u30fb\u30fb<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011\u00a0\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>getDay()\u3067\u65e5\u4ed8\u306f\u53d6\u5f97\u3067\u304d\u306a\u3044<\/h1>\n<p>\u3082\u3046\u3072\u3068\u3064<code>Date()<\/code>\u3067\u306e\u30cf\u30de\u30ea\u3069\u3053\u308d\u3067\u3059\u3002<\/p>\n<p><code>Date()<\/code>\u3092\u4f7f\u3063\u3066\u65e5\u4ed8\u3092\u53d6\u5f97\u3059\u308b\u3068\u304d\u76f4\u611f\u7684\u306b\u6b21\u306e\u3088\u3046\u306b\u601d\u3044\u6d6e\u304b\u3079\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3053\u308c\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<ul>\n<li>\u6642\u9593\u3092\u53d6\u5f97\uff1a getHours()<\/li>\n<li>\u5206\u3092\u53d6\u5f97\uff1a getMinutes()<\/li>\n<li>\u6708\u3092\u53d6\u5f97\uff1a getMonth()<\/li>\n<li>\u65e5\u4ed8\u3092\u53d6\u5f97\uff1a <span style=\"text-decoration: underline;\">getDay()<\/span> \ud83d\udc48 <strong>\u3053\u308c\u306f\u9593\u9055\u3044\u3067\u3059<\/strong><\/li>\n<\/ul>\n<p>\u306a\u305c\u306a\u3089\u3001<code>getDay()<\/code>\u306f<strong>\u65e5\u4ed8\u3092\u53d6\u5f97\u3059\u308b\u3082\u306e\u3067\u306f\u306a\u304f\u3001\u66dc\u65e5\uff08\u6570\u5b57\uff09\u3092\u53d6\u5f97\u3059\u308b\u3082\u306e<\/strong>\u3060\u304b\u3089\u3067\u3059\u3002\uff08\u306a\u305c\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u540d\u306b\u3057\u3066\u3057\u307e\u3063\u305f\u306e\u304b\u30fb\u30fb\u30fb\ud83d\ude02\uff09<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u6b21\u306e\u3088\u3046\u306b\u3059\u308b\u3068\u3046\u307e\u304f\u3044\u304d\u305d\u3046\u3067\u3059\u304c\u3001\u671f\u5f85\u3057\u305f\u52d5\u304d\u306b\u306f\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<pre><strong>\/\/ \u26a0 \u3053\u308c\u306f\u9593\u9055\u3063\u305f\u4f8b\u3067\u3059<\/strong>\r\n\r\nconst dt = new Date();\r\nconst day = <strong>dt.getDay();<\/strong> \/\/ \ud83d\udc48 \u3053\u308c\u3067\u306f\u65e5\u4ed8\u306f\u53d6\u5f97\u3067\u304d\u307e\u305b\u3093<\/pre>\n<p>\u6b63\u3057\u304f\u306f\u3001<code>getDate()<\/code>\u3067\u3059\u3002<\/p>\n<pre>const dt = new Date();\r\nconst day = <strong>dt.getDate()<\/strong>; \/\/ \u3053\u308c\u3067\u65e5\u4ed8\u304c\u53d6\u5f97\u3067\u304d\u307e\u3059<\/pre>\n<p>\u307e\u305f\u3001\u5e74\u3092\u53d6\u5f97\u3059\u308b\u5834\u5408\u3082<code>getYear()<\/code>\u3067\u306f\u306a\u304f<code>getFullYear()<\/code>\u3092\u4f7f\u308f\u306a\u3044\u3068\u3044\u3051\u306a\u3044\u306e\u3067\u3001\u3055\u3089\u306b\u6df7\u4e71\u3055\u305b\u3089\u308c\u307e\u3059\u306d\u30fb\u30fb\u30fb<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u5148\u307b\u3069\u306e<code>getMonth()<\/code>\u306e\u3053\u3068\u3082\u3042\u308a\u307e\u3059\u3057\u3001<code>JavaScript<\/code>\u3067\u65e5\u4ed8\u3092\u6271\u3046\u5834\u5408\u306f <strong><a href=\"https:\/\/momentjs.com\/\" target=\"_blank\" rel=\"noopener noreferrer\">moment<\/a><\/strong> \u306a\u3069\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u4f7f\u3046\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011\u00a0\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>typeof\u3067\u306f\u3001\u914d\u5217\u304b\u3069\u3046\u304b\u306f\u30c1\u30a7\u30c3\u30af\u3067\u304d\u306a\u3044<\/h1>\n<p><code>JavaScript<\/code>\u306b\u306f\u3001\u300c<strong>\u5909\u6570\u306e\u4e2d\u8eab\u304c\u3069\u3093\u306a\u30bf\u30a4\u30d7\u306e\u3082\u306e\u304b<\/strong>\u300d\u3092\u53d6\u5f97\u3067\u304d\u308b<code>typeof<\/code>\u3068\u3044\u3046\u3082\u306e\u304c\u7528\u610f\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f7f\u3044\u65b9\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>const test = '\u30c6\u30b9\u30c8';\r\n\r\nif(<strong>typeof<\/strong> test === 'string') {\r\n\r\n    console.log('\u5909\u6570\u306e\u4e2d\u8eab\u306f\u6587\u5b57\u5217\u3067\u3059');\r\n\r\n}<\/pre>\n<p>\u3057\u304b\u3057\u3001\u3053\u3053\u306b\u3082\u7f60\u304c\u6f5c\u3093\u3067\u3044\u307e\u3059\u3002<br \/>\n\u305d\u308c\u306f\u3001<strong>\u5909\u6570\u306e\u4e2d\u8eab\u304c\u914d\u5217\u306e\u3068\u304d\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3067\u306f\u3001\u9593\u9055\u3063\u305f\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>\/\/ \u26a0\u3053\u308c\u306f\u9593\u9055\u3063\u305f\u4f8b\u3067\u3059\u3002<\/strong>\r\n\r\nconst colors = ['\u8d64', '\u9752', '\u9ec4'];\r\n\r\nif<strong>(typeof colors === 'array')<\/strong> {\r\n\r\n    console.log('\u5909\u6570\u306f\u914d\u5217\u306a\u306e\u306b\u3001\u3053\u3053\u306f\u901a\u308a\u307e\u305b\u3093');\r\n\r\n}<\/pre>\n<p>\u5148\u307b\u3069\u306e\u6587\u5b57\u5217\u306e\u4f8b\u3092\u898b\u308b\u3068\u3001\u4e0a\u306e\u30b3\u30fc\u30c9\u306f\u4e00\u898b\u3046\u307e\u304f\u3044\u304d\u305d\u3046\u3067\u3059\u304c\u3001\u671f\u5f85\u901a\u308a\u306e\u52d5\u304d\u306b\u306f\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u306a\u305c\u306a\u3089\u3001<strong>\u914d\u5217\u306b\u300ctypeof\u300d\u3092\u4f7f\u3063\u3066\u3082\u300cobject\u300d\u304c\u8fd4\u3063\u3066\u304f\u308b\u304b\u3089\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3064\u307e\u308a\u3001<code>typeof<\/code>\u3067\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u914d\u5217\u306e\u9055\u3044\u3092\u533a\u5225\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u306a\u3044\u3068\u3044\u3046\u610f\u5473\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u914d\u5217\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u304b\uff1f\u3067\u3059\u304c\u3001\u4ee5\u4e0b\uff12\u3064\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\uff08\uff11\uff09instanceof \u3067\u6bd4\u8f03\u3059\u308b<\/strong><\/p>\n<p><code>instanceof<\/code>\u3092\u4f7f\u3048\u3070\u3001\u305d\u306e\u5909\u6570\u304c\u300c<strong>\u4f55\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u306a\u306e\u304b<\/strong>\u300d\u304c\u308f\u304b\u308b\u306e\u3067\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>Array<\/code>\u306e\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u3053\u3068\u3067\u914d\u5217\u304b\u3069\u3046\u304b\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n<pre>const colors = ['\u8d64', '\u9752', '\u9ec4'];\r\n\r\nif(<strong>colors instanceof Array<\/strong>) {\r\n\r\n    console.log('\u4e2d\u8eab\u306f\u914d\u5217\u3067\u3059');\r\n\r\n}<\/pre>\n<p><strong>\uff08\uff12\uff09isArray()\u3092\u4f7f\u3046<\/strong><\/p>\n<p>\u307e\u305f\u3001<code>isArray()<\/code>\u3092\u4f7f\u3063\u3066\u3082\u540c\u3058\u304f\u914d\u5217\u304b\u3069\u3046\u304b\u306e\u30c1\u30a7\u30c3\u30af\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>const colors = ['\u8d64', '\u9752', '\u9ec4'];\r\n\r\nif(<strong>Array.isArray(colors)<\/strong>) {\r\n\r\n    console.log('\u4e2d\u8eab\u306f\u914d\u5217\u3067\u3059');\r\n\r\n}<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3001<code>null<\/code>\u306e\u5834\u5408\u3067\u3082\u3001<code>typeof<\/code>\u306f<code>object<\/code>\u306b\u306a\u308a\u307e\u3059\u3002<br \/>\n\u53b3\u5bc6\u306b\u8a00\u3046\u3068\u300c<strong>null\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u300d\u3068\u3044\u3046\u3053\u3068\u3067\u9593\u9055\u3063\u3066\u306a\u3044\u3093\u3067\u3057\u3087\u3046\u3051\u3069\u3001\u306a\u305c\u3053\u306e\u4ed5\u69d8\u3067OK\u306b\u306a\u3063\u305f\u306e\u304b\u30fb\u30fb\u30fb\ud83d\ude02<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011 \ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u7a7a\u304b\u3069\u3046\u304b\u306f\u3001\u5de5\u592b\u304c\u5fc5\u8981<\/h1>\n<p>\u4f8b\u3048\u3070\u3001<code>JavaScript<\/code>\u3067\u7a7a\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5b9a\u7fa9\u3059\u308b\u5834\u5408\u3001\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>const obj = {};<\/strong><\/pre>\n<p>\u305d\u3057\u3066\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u7a7a\u304b\u3069\u3046\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u306b\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u3057\u3066\u3057\u307e\u3044\u304c\u3061\u3067\u3059\u304c\u3001<strong>\u3053\u308c\u306f\u6b63\u3057\u304f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/p>\n<pre><strong>\/\/ \u26a0\u3053\u308c\u306f\u9593\u9055\u3063\u305f\u4f8b\u3067\u3059<\/strong>\r\n\r\nconst obj = {};\r\n\r\nif(<strong>obj === {}<\/strong>) {\r\n\r\n    console.log('\u5b9f\u969b\u306b\u306f\u3001\u3053\u3053\u306f\u901a\u308a\u307e\u305b\u3093');\r\n\r\n}<\/pre>\n<p>\u3067\u306f\u3001\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u304b\u3068\u3044\u3046\u3068\u3001<strong>\u300c\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ad\u30fc\u300d\u304c\u3044\u304f\u3064\u5b58\u5728\u3057\u3066\u3044\u308b\u304b\u3067\u30c1\u30a7\u30c3\u30af\u3057\u307e\u3059\u3002<\/strong><\/p>\n<p>\u5b9f\u969b\u306e\u4f8b\u306f\u3053\u3061\u3089\u3067\u3059\u3002<\/p>\n<pre>const obj = {};\r\n\r\nif(<strong>Object.keys(obj).length<\/strong> === 0) {\r\n\r\n    console.log('\u3053\u3053\u306f\u901a\u308a\u307e\u3059\uff08\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u7a7a\u3067\u3059\uff09');\r\n\r\n}<\/pre>\n<p>\u6d41\u308c\u306f\u3053\u3046\u3067\u3059\u3002<\/p>\n<ol>\n<li>Object.keys()\u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5168\u30ad\u30fc\u3092\u53d6\u5f97<\/li>\n<li>\u30ad\u30fc\u306e\u6570\u3092\u300clength\u300d\u3067\u53d6\u5f97<\/li>\n<li>\u305d\u306e\u6570\u304c\u30bc\u30ed\u306a\u3089\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u7a7a<\/li>\n<\/ol>\n<p>\u3053\u308c\u306f\u3001\u4eca\u304b\u3089\u3067\u3082\u5148\u307b\u3069\u306e\u9593\u9055\u3063\u305f\u4f8b\u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u4ed5\u69d8\u5909\u66f4\u3057\u3066\u307b\u3057\u3044\u3050\u3089\u3044\u306e\u843d\u3068\u3057\u7a74\u3067\u3059\uff08\u7b11\uff09<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011\u00a0\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30d4\u30fc\u306f\u3001\u300c\u5168\u304f\u540c\u3058\u3082\u306e\u300d\u306b\u306a\u308b<\/h1>\n<p>\u4f8b\u3048\u3070\u3001<code>obj1<\/code>\u3092\u30b3\u30d4\u30fc\u3057\u3066<code>obj2<\/code>\u3092\u3064\u304f\u308b\u5834\u5408\u3001\u3069\u3046\u3059\u308b\u3067\u3057\u3087\u3046\u304b\u3002<br \/>\n\u3082\u3057\u304b\u3059\u308b\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u76f4\u63a5\u4ee3\u5165\u3059\u308c\u3070\u3044\u3044\u3093\u3058\u3083\uff1f\u3068\u8003\u3048\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u3002<\/p>\n<pre>\/\/ \u26a0\u3053\u308c\u306f\u3059\u3079\u304d\u3067\u306f\u306a\u3044\u66f8\u304d\u65b9\u3067\u3059\r\n\r\nlet obj1 = { name: '\u592a\u90ce' };\r\nlet obj2 = obj1;<\/pre>\n<p>\u3057\u304b\u3057\u3001\u3053\u308c\u306f\u7279\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<br \/>\n\u306a\u305c\u306a\u3089\u3001<strong><code>obj1<\/code>\u3068<code>obj2<\/code>\u306f\u5168\u304f\u540c\u3058\u3082\u306e\u306b\u306a\u308b\u304b\u3089\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3069\u3046\u3044\u3046\u3053\u3068\u304b\u5b9f\u969b\u306b\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001\u7d9a\u304d\u306e\u30b3\u30fc\u30c9\u3068\u3057\u3066<code>obj2<\/code>\u306e<code>name<\/code>\u3060\u3051\u3092\u300c<strong>\u6b21\u90ce<\/strong>\u300d\u306b\u5909\u66f4\u3057\u305f\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre>\/\/ \u26a0\u3053\u308c\u306f\u3059\u3079\u304d\u3067\u306f\u306a\u3044\u66f8\u304d\u65b9\u3067\u3059\r\n\r\nlet obj1 = { name: '\u592a\u90ce' };\r\nlet obj2 = obj1;\r\n\r\n<strong>obj2.name = '\u6b21\u90ce'; \/\/ \ud83d\udc48 obj2 \u306e name \u3060\u3051\u5909\u66f4<\/strong><\/pre>\n<p>\u3059\u308b\u3068\u3001\u306a\u3093\u3068<strong>\u66f8\u304d\u63db\u3048\u3066\u3044\u306a\u3044\u300cobj1\u300d\u306e\u300cname\u300d\u3082\u300c\u6b21\u90ce\u300d\u306b\u5909\u66f4\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3064\u307e\u308a\u3001<code>obj1<\/code>\u3068<code>obj2<\/code>\u306f\u5168\u304f\u540c\u3058\u3082\u306e\u3068\u6271\u308f\u308c\u308b\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\uff08\u53c2\u7167\u6e21\u3057\u307f\u305f\u3044\u306a\u3053\u3068\u3067\u3059\u306d\uff09<\/p>\n<p>\u3067\u306f\u3001\u89e3\u6c7a\u6cd5\u3067\u3059\u304c\u3053\u3061\u3089\u3082\uff12\u3064\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><strong>\uff08\uff11\uff09\u4e00\u5ea6JSON\u306b\u5909\u63db\u3057\u3066\u3001\u5143\u306b\u623b\u3059<\/strong><\/p>\n<p>\u3053\u308c\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4e00\u5ea6<code>JSON<\/code>\uff08\u3064\u307e\u308a\u3001\u6587\u5b57\u5217\uff09\u306b\u5909\u63db\u3057\u3066\u3001\u307e\u305f\u5143\u306b\u623b\u3059\u3053\u3068\u3067\u300c\u4e2d\u8eab\u304c\u540c\u3058\u3060\u3051\u3069\u3001\u65b0\u3057\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u300d\u3092\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>const obj = { name: '\u592a\u90ce' };\r\nconst newObj = <strong>JSON.parse(JSON.stringify(obj));<\/strong><\/pre>\n<p>\u6d41\u308c\u306f\u6b21\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n<ol>\n<li>JSON.stringify() \u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092JSON\uff08\u6587\u5b57\u5217\uff09\u306b\u3059\u308b<\/li>\n<li>\u305d\u3057\u3066\u3001\u305d\u306e\u5024\u3092\u3059\u3050 JSON.parse() \u3067\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u623b\u3059<\/li>\n<li>\u65b0\u3057\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u5b8c\u6210<\/li>\n<\/ol>\n<p><strong>\uff08\uff12\uff09Object.assign() \u3092\u3064\u304b\u3046<\/strong><\/p>\n<p><code>ES 6<\/code>\u3068\u3057\u3066\u65b0\u3057\u304f\u8ffd\u52a0\u3055\u308c\u305f<code>Object.assign()<\/code>\u306f\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u7d50\u5408\u3059\u308b\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u304c\u3001\u3053\u308c\u3092\u4f7f\u3063\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30b3\u30d4\u30fc\u3092\u3064\u304f\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre>const obj = { name: '\u592a\u90ce' };\r\nconst newObj = <strong>Object.assign({}, obj)<\/strong>;<\/pre>\n<p>\u3064\u307e\u308a\u3001\u300c<strong>\u7a7a\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 + \u30b3\u30d4\u30fc\u3057\u305f\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u300d\u3067\u7d50\u5408\u3057\u3066\u3044\u308b\u308f\u3051\u3067\u3059\u306d\u3002<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011\u00a0\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u9806\u756a\u3092\u4fdd\u8a3c\u3057\u3066\u3044\u306a\u3044<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3042\u3063\u305f\u3068\u3057\u307e\u3059\u3002<\/p>\n<pre>const mixObj = {\r\n    <strong>name<\/strong>: '\u592a\u90ce',\r\n    <strong>1<\/strong>: 'ONE',\r\n    <strong>id<\/strong>: 5\r\n};<\/pre>\n<p>\u305d\u3057\u3066\u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u30eb\u30fc\u30d7\u3067\u5168\u3066\u53d6\u308a\u51fa\u3059\u5834\u5408\u3092\u8003\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>for(let key in mixObj) {\r\n\r\n    console.log(key);\r\n\r\n}<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001\u30ad\u30fc\u306f\u3069\u3093\u306a\u9806\u756a\u3067\u53d6\u5f97\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u304b\u3002<\/p>\n<p>\u304a\u305d\u3089\u304f\u30b3\u30fc\u30c9\u3067\u66f8\u3044\u305f\u3068\u304a\u308a<strong>\u300cname\u300d\u300c1\u300d\u300cid\u300d\u306e\u9806\u756a\u306b\u306a\u308b\u3068\u601d\u3046\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u5b9f\u969b\u306f\u305d\u3046\u306f\u306a\u308a\u307e\u305b\u3093\u3002<\/strong><\/p>\n<p>\u306a\u3093\u3068\u3001\u6b21\u306e\u3088\u3046\u306b\u300c\uff11\u300d\u304c\u5148\u982d\u306b\u304d\u3066\u3057\u307e\u3044\u307e\u3059\u3002<\/p>\n<ul>\n<li>1<\/li>\n<li>name<\/li>\n<li>id<\/li>\n<\/ul>\n<p>\u3064\u307e\u308a\u3001<strong>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30c7\u30fc\u30bf\u306e\u9806\u756a\u3092\u4fdd\u8a3c\u3057\u3066\u3044\u306a\u3044<\/strong>\u306e\u3067\u3001\u3082\u3057<strong>\u9806\u756a\u304c\u91cd\u8981\u306a\u5834\u5408\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f7f\u3046\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/strong><\/p>\n<p>\u3067\u306f\u3001\u3069\u306e\u3088\u3046\u306b\u3059\u308b\u304b\u3068\u3044\u3046\u3068<strong>\u7b54\u3048\u306f\u300c\u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u300d\uff08\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u914d\u5217\uff09\u3067\u3059\u3002<\/strong><\/p>\n<p>\u5b9f\u969b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>\/\/ \u30b3\u30ec\u30af\u30b7\u30e7\u30f3\u3067\u5b9a\u7fa9\r\nconst collection = <strong>[<\/strong>\r\n<strong>    { key: 'name', value: '\u592a\u90ce' },<\/strong>\r\n<strong>    { key: 1, value: 'ONE' },<\/strong>\r\n<strong>    { key: 'id', value: 5 },<\/strong>\r\n<strong>]<\/strong>;\r\n\r\nfor(let i in collection) {\r\n\r\n    const data = collection[i];\r\n    console.log(<strong>data.key<\/strong>); <strong>\/\/ \ud83d\udc48 \u9806\u756a\u306f\u305d\u306e\u307e\u307e\u4fdd\u6301\u3055\u308c\u307e\u3059<\/strong>\r\n\r\n}<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u30c7\u30fc\u30bf\u3092\u914d\u5217\u5316\u3059\u308b\u3053\u3068\u3067\u30eb\u30fc\u30d7\u306e\u9806\u756a\u3092\u56fa\u5b9a\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011 \ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>for ~ of \u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u4f7f\u3048\u306a\u3044<\/h1>\n<p><code>ES 6<\/code> \u306e\u65b0\u3057\u3044\u66f8\u304d\u65b9\u306b<code>for ~ of<\/code>\u3068\u3044\u3046\u306e\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f\u3001\u5024\u3092\u3072\u3068\u3064\u305a\u3064\u30eb\u30fc\u30d7\u3067\u53d6\u5f97\u3067\u304d\u308b\u66f8\u304d\u65b9\u306a\u306e\u3067\u3059\u304c\u3001\u5b9f\u306f\u3053\u308c\u306b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u4f7f\u3048\u307e\u305b\u3093\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>\/\/ \u26a0\u3053\u308c\u306f\u9593\u9055\u3063\u305f\u4f8b\u3067\u3059<\/strong>\r\n\r\nconst alcohol = {\r\n    beer: '\u30d3\u30fc\u30eb',\r\n    wine: '\u30ef\u30a4\u30f3',\r\n    cocktail: '\u30ab\u30af\u30c6\u30eb'\r\n};\r\n\r\nfor(<strong>let value of alcohol)<\/strong> { <strong>\/\/ \ud83d\udc48 \u30a8\u30e9\u30fc\u306b\u306a\u308b<\/strong>\r\n\r\n    \/\/\r\n\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u4e00\u898b\u3046\u307e\u304f\u3044\u304d\u305d\u3046\u3067\u3059\u304c\u3001\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u3002<\/p>\n<pre><strong>Uncaught TypeError: alcohol is not iterable<\/strong><\/pre>\n<p>\u610f\u5473\u3068\u3057\u3066\u306f\u3001\u300c<strong>\u305d\u306e\u30c7\u30fc\u30bf\u306f\u30eb\u30fc\u30d7\u3067\u304d\u306a\u3044\u3088\ud83d\ude2b<\/strong>\u300d\u3068\u3044\u3046\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u3069\u3046\u3059\u308b\u304b\u3068\u3044\u3046\u3068\u6b21\u306e\u3088\u3046\u306b<code>Object.entries()<\/code>\u3067<code>key<\/code>\u3068<code>value<\/code>\u306b\u5206\u5272\u3057\u306a\u304c\u3089\u30eb\u30fc\u30d7\u3092\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>for(const [key, value] of Object.entries(alcohol)) {<\/strong>\r\n\r\n    console.log(key, value);\r\n\r\n}<\/pre>\n<p>\u306a\u304a\u3001<code>for ~ in<\/code>\u3067\u30ad\u30fc\u3092\u53d6\u5f97\u3057\u306a\u304c\u3089\u30eb\u30fc\u30d7\u3059\u308b\u5f93\u6765\u306e\u65b9\u6cd5\u3082\u4f7f\u3048\u307e\u3059\u3002<\/p>\n<pre><strong>for(let key in alcohol) {<\/strong>\r\n\r\n    const value = alcohol[key];\r\n    console.log(key, value);\r\n\r\n}<\/pre>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011 \ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>replace() \u306f\u57fa\u672c\u7684\u306b\u3072\u3068\u3064\u3060\u3051\u3057\u304b\u5165\u308c\u66ff\u3048\u3066\u304f\u308c\u306a\u3044<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u6587\u5b57\u5217\u306e\u4e2d\u304b\u3089<code>1<\/code>\u3092<code>_one_<\/code>\u306b\u5165\u308c\u66ff\u3048\u308b\u5834\u5408\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>const text = '123123123';<\/pre>\n<p><code>JavaScript<\/code>\u306b\u306f\u3001<code>replace()<\/code>\u3068\u3044\u3046\u30e1\u30bd\u30c3\u30c9\u3092\u304c\u3042\u308b\u306e\u3067\u3053\u308c\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u6b63\u898f\u8868\u73fe\u3067\u5165\u308c\u66ff\u3048\u3092\u3057\u307e\u3059\u3002<\/p>\n<pre>const text = '123123123';\r\nconst text2 = <strong>text.replace(\/1\/, '_ONE_');<\/strong><\/pre>\n<p>\u3057\u304b\u3057\u3001\u3053\u3053\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u306a\u305c\u306a\u3089\u3001<strong>JavaScript\u306e replace() \u304c\u5f71\u97ff\u3092\u4e0e\u3048\u308b\u306e\u306f\u3001\u901a\u5e38\u306f\u6700\u521d\u306e\uff11\u30f6\u6240\u3060\u3051<\/strong>\u3060\u304b\u3089\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001<code>text2<\/code>\u306f\u300c<strong>_ONE_23123123<\/strong>\u300d\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3069\u3046\u3059\u308b\u304b\u3068\u3044\u3046\u3068\u3001\u6b63\u898f\u8868\u73fe\u306b<code>g<\/code>\u3092\u3064\u3051\u3066\u3042\u3052\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>const text = '123123123';\r\nconst text2 = text.replace(\/1\/<strong>g<\/strong>, '_ONE_'); \/\/ \ud83d\udc48 g \u3092\u3064\u3051\u308b<\/pre>\n<p>\u3053\u308c\u3067\u5b9f\u884c\u3059\u308b\u3068<code>text2<\/code>\u306f\u3001\u300c<strong>_ONE_23_ONE_23_ONE_23<\/strong>\u300d\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011 \ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>\u968e\u5c64\u304c\u6df1\u3044\u30c7\u30fc\u30bf\u306eif\u6587\u306f\u3001\u6ce8\u610f\u304c\u5fc5\u8981<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u3044\u304f\u3064\u304b\u30c7\u30fc\u30bf\u304c\u5165\u3063\u3066\u3044\u3066\u3001\u305d\u306e\u4e2d\u8eab\u306e\u5024\u3092<code>if\u6587<\/code>\u3067\u6bd4\u8f03\u3059\u308b\u5834\u5408\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>const item = {\r\n    name: '\u5546\u54c1\u540d',\r\n    price: 1000\r\n};\r\n\r\n<strong>if(item.name !== '')<\/strong> {\r\n\r\n    \/\/\r\n\r\n}<\/pre>\n<p>\u5b9f\u306f\u3053\u306e\u5834\u5408\u3067\u306f\u3001\u4f55\u3082\u554f\u984c\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u3057\u304b\u3057\u3001\u554f\u984c\u3068\u306a\u308b\u30d1\u30bf\u30fc\u30f3\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u305d\u308c\u306f\u3001<code>null<\/code>\u3084<code>undefined<\/code>\u304c\u5165\u3063\u3066\u304f\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u3082\u3057\u4ee5\u4e0b\u306e\u3088\u3046\u306b<code>item<\/code>\u306b\u521d\u671f\u5024\u3067<code>null<\/code>\u304c\u5165\u3063\u3066\u3044\u305f\u3068\u3057\u3066\u3001\u305d\u306e\u5f8c\u3082\u30c7\u30fc\u30bf\u304c\u5909\u66f4\u306b\u306a\u3089\u306a\u304b\u3063\u305f\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre><strong>let item = null;<\/strong>\r\n\r\n\/\/ \u305d\u3057\u3066\u3001item \u306e\u30c7\u30fc\u30bf\u304c\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f\u3089\u30fb\u30fb\u30fb\r\n\r\n<strong>if(item.name !== '')<\/strong> { \/\/ \u3053\u3053\u306f\u30a8\u30e9\u30fc\u306b\u306a\u308a\u307e\u3059\r\n\r\n    \/\/\r\n\r\n}<\/pre>\n<p>\u3053\u306e\u5834\u5408\u3001\u300c<strong>Uncaught TypeError: Cannot read property &#8216;name&#8217; of null<\/strong>\u300d\u3068\u3044\u3046\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001\u300c<code>null<\/code>\u306b\u306f\u3001<code>name<\/code>\u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u306a\u3044\u3088\u30fb\u30fb\u30fb\ud83d\ude2b\u300d\u3068\u8a00\u308f\u308c\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u305d\u306e\u305f\u3081\u3001\u3053\u3046\u3044\u3063\u305f\u5834\u5408\u3067\u306f\u6b21\u306e\u3088\u3046\u306b<code>if\u6587<\/code>\u306e\u6761\u4ef6\u3092\u3072\u3068\u3064\u5897\u3084\u3057\u3066\u4fdd\u967a\u3092\u304b\u3051\u3066\u304a\u304f\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n<pre><strong>if(item &amp;&amp; item.name !== '') {<\/strong> \/\/ \u3053\u3063\u3061\u304c\u30d9\u30bf\u30fc\r\n\r\n   \/\/\r\n\r\n}<\/pre>\n<p>\u3053\u308c\u306f\u3001\uff11\u3064\u76ee\u306e<code>item<\/code>\u3067\u5024\u304c<code>null<\/code>\u3084<code>undefined<\/code>\u306e\u5834\u5408\u306f<strong>\u305d\u3053\u3067\u6bd4\u8f03\u304c\u7d42\u4e86\u3059\u308b<\/strong>\u305f\u3081\u3001\uff12\u3064\u76ee\u306e<code>item.name<\/code>\u307e\u3067\u884c\u304b\u305a\u3001\u7d50\u679c\u3068\u3057\u3066\u30a8\u30e9\u30fc\u306f\u51fa\u306a\u3044\u3068\u3044\u3046\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011 \ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>sort()\u306f\u5148\u982d\u306e\u6587\u5b57\u304b\u3089\u4e26\u3079\u66ff\u3048\u3092\u3059\u308b<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u3044\u304f\u3064\u304b\u306e\u6570\u5b57\u304c\u5165\u3063\u305f\u914d\u5217\u304c\u3042\u3063\u3066\u3001\u305d\u306e\u6570\u5b57\u3092<code>sort()<\/code>\u3067\u4e26\u3079\u66ff\u3048\u308b\u5834\u5408\u306f\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u5b9f\u969b\u306e\u4f8b\u3092\u898b\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><strong>\/\/ \u26a0\u3053\u308c\u306f\u9593\u9055\u3063\u305f\u4f8b\u3067\u3059<\/strong>\r\n\r\nconst numbers = [1, 3, 11, 8, 13];\r\nconst sortedNumbers = <strong>numbers.sort()<\/strong>; \/\/ \ud83d\udc48 \u6570\u5b57\u306e\u9806\u306b\u306f\u306a\u3089\u306a\u3044<\/pre>\n<p>\u7d50\u679c\u3068\u3057\u3066<code>sortedNumbers<\/code>\u306f\u6b21\u306e\u3088\u3046\u306b\u4e26\u3079\u66ff\u3048\u3089\u308c\u308b\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>[1, 11, 13, 3, 8] <\/strong>\/\/ \ud83d\udc48 \u601d\u3063\u3066\u305f\u306e\u3068\u9055\u3046\u30fb\u30fb\u30fb<\/pre>\n<p>\u3064\u307e\u308a\u3001<strong>\u5148\u982d\u306e\u6587\u5b57\u304b\u3089\u9806\u306b\u4e26\u3079\u66ff\u3048\u3092\u3057\u3066\u3057\u307e\u3046\u308f\u3051\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3067\u306f\u3001\u5168\u4f53\u3092\u307f\u3066\u9806\u756a\u306b\u4e26\u3079\u66ff\u3048\u3092\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3044\u3044\u304b\u3068\u3044\u3046\u3068\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u95a2\u6570\u3092\u4f7f\u3063\u3066\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre>const numbers = [1, 3, 11, 8, 13];\r\nconst sortedNumbers = <strong>numbers.sort((a, b) =&gt; {<\/strong>\r\n\r\n<strong>    return a - b;<\/strong>\r\n\r\n<strong>});<\/strong><\/pre>\n<p>\u7d50\u679c\u306f\u3001\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre>[1, 3, 8, 11, 13]<\/pre>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011 \ud83d\ude2b\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>indexOf(), inclues()\u306e\u30c7\u30fc\u30bf\u6bd4\u8f03\u306f\u53b3\u683c<\/h1>\n<p>\u4f8b\u3048\u3070\u3001\u914d\u5217\u306e\u4e2d\u306b\u7279\u5b9a\u306e\u5024\u304c\u5165\u3063\u3066\u3044\u308b\u306e\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u3001<code>indexOf()<\/code>\u3084<code>inludes()<\/code>\u3092\u4f7f\u3044\u307e\u3059\u304c\u3001\u3053\u306e\u5834\u5408\u306f\u578b\u306e\u30c1\u30a7\u30c3\u30af\u3082\u6c17\u3092\u3064\u3051\u3066\u304a\u304b\u306a\u3044\u3068\u671f\u5f85\u901a\u308a\u306b\u52d5\u304b\u306a\u3044\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3001\u307e\u305a\u9593\u9055\u3063\u305f\u4f8b\u3092\u307f\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre>const numbers = [\r\n    1,\r\n    <strong>'2'<\/strong>, \/\/ \ud83d\udc48 \u6587\u5b57\u5217\r\n    3\r\n];\r\n\r\nif(<strong>numbers.indexOf(2)<\/strong> &gt; -1) {\r\n\r\n    console.log('\u3053\u3053\u306f\u901a\u308a\u307e\u305b\u3093');\r\n\r\n}<\/pre>\n<p><code>numbers<\/code>\u306e\u4e2d\u306b\u300c\uff12\u300d\u304c\u5165\u3063\u3066\u3044\u308c\u3070<code>if\u6587<\/code>\u306e\u4e2d\u3092\u901a\u308b\u306f\u305a\u3067\u3059\u304c\u3001\u5b9f\u306f\u305d\u3046\u306f\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n<p>\u306a\u305c\u306a\u3089\u3001<strong>\u30c7\u30fc\u30bf\u306e\u6bd4\u8f03\u3092\u3057\u3066\u3044\u308b\u300c\uff12\u300d\u306f\u6587\u5b57\u5217\u3068\u6570\u5024\u306e\u6bd4\u8f03\u306b\u306a\u3063\u3066\u3044\u308b\u304b\u3089\u3067\u3059\u3002<\/strong><\/p>\n<p>\u3064\u307e\u308a\u3001\u3082\u3057\u5148\u307b\u3069\u306e\u4f8b\u3067\u300c\uff12\u300d\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u306e\u304b\u3092\u30c1\u30a7\u30c3\u30af\u3059\u308b\u5834\u5408\u306f<code>indexOf()<\/code>\u306e\u4e2d\u306b\u3044\u308c\u308b\u300c\uff12\u300d\u3082\u6587\u5b57\u5217\u306b\u3057\u306a\u3044\u3068\u3044\u3051\u307e\u305b\u3093\u3002<\/p>\n<pre>if(<strong>numbers.indexOf('2')<\/strong> &gt; -1) {\r\n\r\n    console.log('\u3053\u3063\u3061\u306f\u901a\u308a\u307e\u3059');\r\n\r\n}<\/pre>\n<p>\u305d\u3057\u3066\u3001\u3053\u308c\u3068\u540c\u3058\u3053\u3068\u304c<code>includes()<\/code>\u306b\u3082\u8d77\u3053\u308a\u307e\u3059\u3002<\/p>\n<pre><strong>if(numbers.includes(2)) {<\/strong>\r\n\r\n<strong>    console.log('\u3053\u3053\u306f\u901a\u308a\u307e\u305b\u3093');<\/strong>\r\n\r\n<strong>}<\/strong>\r\n\r\n<strong>if(numbers.includes('2')) {<\/strong>\r\n\r\n<strong>    console.log('\u3053\u3063\u3061\u306f\u901a\u308a\u307e\u3059');<\/strong>\r\n\r\n<strong>}<\/strong><\/pre>\n<p>\u7279\u306bMySQL\u306e\u30c9\u30e9\u30a4\u30d0\u30fc\u306b\u300c<strong>mysqlnd<\/strong>\u300d\u3067\u306f\u306a\u304f\u3001\u300c<strong>mysqli<\/strong>\u300d\u3092\u4f7f\u3063\u3066\u3044\u308b\u5834\u5408\u3067\u306f\u3001<code>integer<\/code>\u3067\u3042\u3063\u3066\u3082\u81ea\u52d5\u3067\u6570\u5024\u306b\u5909\u63db\u3057\u3066\u304f\u308c\u306a\u3044\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002<\/p>\n<p>\u3010\u30cf\u30de\u30ea\u5ea6\u3011 \ud83d\ude2b\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b\ud83d\ude2b<\/p>\n<h1>\u304a\u308f\u308a\u306b<\/h1>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067\u3001\u4eca\u56de\u306f\u5c11\u3057\u8da3\u5411\u3092\u5909\u3048\u3066\u300c<strong>JavaScript\u306e\u30cf\u30de\u30ea\u3069\u3053\u308d<\/strong>\u300d\u306e\u307e\u3068\u3081\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u52c9\u5f37\u3092\u306f\u3058\u3081\u3066\u3059\u3050\u306e\u5834\u5408\u306f\u3001\u3053\u3046\u3044\u3063\u305f\u30a4\u30ec\u30ae\u30e5\u30e9\u30fc\u306a\u5185\u5bb9\u306e\u305b\u3044\u3067\u4e00\u65e5\u4e2dGoogle\u691c\u7d22\u3059\u308b\u3053\u3068\u306b\u306a\u3063\u305f\u308a\u3001\u30b3\u30fc\u30c9\u306f\u4f55\u3082\u66f8\u3044\u3066\u306a\u3044\u306e\u306b\u6642\u9593\u3060\u3051\u304c\u904e\u304e\u3066\u3044\u3063\u3066\u76f8\u5f53\u7126\u308b\u3053\u3068\u3082\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u305d\u3046\u3044\u3063\u305f\u300c\u3057\u306a\u304f\u3066\u3044\u3044\u82e6\u52b4\u300d\u304c\u4eca\u56de\u306e\u8a18\u4e8b\u3067\u5c11\u3057\u3067\u3082\u306a\u304f\u306a\u308c\u3070\u5b09\u3057\u3044\u3067\u3059\u3002<\/p>\n<p>\u305d\u3057\u3066\u3001\u3082\u3057\u5c11\u3057\u3067\u3082\u6642\u9593\u3092\u30b7\u30e7\u30fc\u30c8\u30ab\u30c3\u30c8\u3067\u304d\u305f\u3089\u3001\u305c\u3072\u305d\u306e\u5206\u8da3\u5473\u3084\u697d\u3057\u3044\u3053\u3068\u306b\u4f7f\u3063\u3066\u304f\u3060\u3055\u3044 \ud83d\ude0a\ud83d\udc4d<\/p>\n<p>\u3067\u306f\u3067\u306f\u301c\u2757<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3467 aligncenter\" src=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9.png\" alt=\"\" width=\"216\" height=\"320\" srcset=\"https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9.png 216w, https:\/\/blog.capilano-fw.com\/wp-content\/uploads\/2019\/04\/no_9-203x300.png 203w\" sizes=\"auto, (max-width: 216px) 100vw, 216px\" \/>\u300c\u4e00\u65e5\u4e2d\u30cf\u30de\u3063\u3066\u305f\u306e\u306b\u3001<br \/>\n\u5bdd\u3066\u8d77\u304d\u305f\u3089\uff15\u5206\u3067\u89e3\u6c7a\u3057\u305f\u308a\u3057\u307e\u3059\u3088\u306d\uff08\u4e0d\u601d\u8b70\uff01\uff09\ud83d\ude02\u300d<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3055\u3066\u3055\u3066\u3001\u79c1\u3054\u3068\u304d\u304c\u30fb\u30fb\u30fb\u3068\u3044\u3046\u304a\u8a71\u306a\u306e\u3067\u3059\u304c\u3001\u5b9f\u306f\u5c11\u3057\u524d\u304b\u3089\u500b\u4eba\u3067\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u30aa\u30f3\u30e9\u30a4\u30f3\u30fb\u30ec\u30c3\u30b9\u30f3\u3092\u3084\u3089\u305b\u3066\u3082\u3089\u3063\u3066\u3044\u307e\u3059\u3002 \u305d\u3057\u3066\u3001\u5c11\u3057\u524d\u3042\u308b\u751f\u5f92\u3055\u3093\u304b\u3089\u300c &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.capilano-fw.com\/?p=7724\" class=\"more-link\"><span class=\"screen-reader-text\">&#8220;JavaScript\u306e\u30cf\u30de\u308a\u3069\u3053\u308d\u516811\u4ef6\uff01&#8221; \u306e<\/span>\u7d9a\u304d\u3092\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":7729,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-7724","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7724","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7724"}],"version-history":[{"count":8,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7724\/revisions"}],"predecessor-version":[{"id":7798,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/posts\/7724\/revisions\/7798"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=\/wp\/v2\/media\/7729"}],"wp:attachment":[{"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7724"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7724"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.capilano-fw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7724"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}