{"id":81,"date":"2016-07-14T19:10:05","date_gmt":"2016-07-14T19:10:05","guid":{"rendered":"http:\/\/markcarlson.io\/?p=81"},"modified":"2016-07-14T19:10:05","modified_gmt":"2016-07-14T19:10:05","slug":"new-javascript-foreach-iterator","status":"publish","type":"post","link":"https:\/\/mc.dev\/new-javascript-foreach-iterator\/","title":{"rendered":"New Javascript ForEach iterator"},"content":{"rendered":"<p>Have to start getting used to some iterator syntax. \u00a0Here&#8217;s how we USED to do it:<\/p>\n<pre class=\"p1\"> \r\nfor (let color in colors) {\r\n            let colorObj = {};\r\n\r\n            colorObj.code = colors[color].colorPrdId;\r\n            colorObj.name = colors[color].colorName;\r\n            colorObj.imgSwatch = colors[color].imgSwatch;\r\n\r\n            collection.push(colorObj);\r\n        }\r\n<\/pre>\n<p>Here&#8217;s the new way to code\u00a0the same thing:<\/p>\n<pre class=\"p1\">        colors.forEach(function (color) {\r\n            collection.push({\r\n                code: color.colorPrdId,\r\n                name: color.colorName,\r\n                imgSwatch: color.imgSwatch\r\n            });\r\n        });\r\n<\/pre>\n<p><a href=\"https:\/\/hacks.mozilla.org\/2015\/04\/es6-in-depth-iterators-and-the-for-of-loop\/\">More about modern iterators<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have to start getting used to some iterator syntax. \u00a0Here&#8217;s how we USED to do it: for (let color in colors) { let colorObj = {}; colorObj.code = colors[color].colorPrdId; colorObj.name = colors[color].colorName; colorObj.imgSwatch = colors[color].imgSwatch; collection.push(colorObj); } Here&#8217;s the new way to code\u00a0the same thing: colors.forEach(function (color) { collection.push({ code: color.colorPrdId, name: color.colorName, imgSwatch: color.imgSwatch [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-81","post","type-post","status-publish","format-standard","category-ui","czr-hentry"],"_links":{"self":[{"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/posts\/81","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/comments?post=81"}],"version-history":[{"count":1,"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/posts\/81\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/posts\/81\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/media?parent=81"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/categories?post=81"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mc.dev\/wp-json\/wp\/v2\/tags?post=81"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}