Bad code in a Waypoint snippet #4434

Replaced .map() method with .forEach()
This commit is contained in:
alvynmcq
2015-11-14 22:50:41 +00:00
parent 1c790d66be
commit d7ca38bf47

View File

@ -160,14 +160,14 @@
"title": "Convert JSON Data to HTML", "title": "Convert JSON Data to HTML",
"description": [ "description": [
"Now that we're getting data from a JSON API, let's display it in our HTML.", "Now that we're getting data from a JSON API, let's display it in our HTML.",
"We can use the <code>.map()</code> method to loop through our data and modify our HTML elements.", "We can use the <code>.forEach()</code> method to loop through our data and modify our HTML elements.",
"First, let's declare an html variable with <code>var html = \"\";</code>.", "First, let's declare an html variable with <code>var html = \"\";</code>.",
"Then, let's loop through our JSON, adding more HTML to that variable. When the loop is finished, we'll render it.", "Then, let's loop through our JSON, adding more HTML to that variable. When the loop is finished, we'll render it.",
"Here's the code that does this:", "Here's the code that does this:",
"<code>json.map(function(val) {</code>", "<code>json.forEach(function(val) {</code>",
"<code>&nbsp;&nbsp;var keys = Object.keys(val);</code>", "<code>&nbsp;&nbsp;var keys = Object.keys(val);</code>",
"<code>&nbsp;&nbsp;html += \"&lt;div class = 'cat'&gt;\";</code>", "<code>&nbsp;&nbsp;html += \"&lt;div class = 'cat'&gt;\";</code>",
"<code>&nbsp;&nbsp;keys.map(function(key) {</code>", "<code>&nbsp;&nbsp;keys.forEach(function(key) {</code>",
"<code>&nbsp;&nbsp;&nbsp;&nbsp;html += \"&lt;b&gt;\" + key + \"&lt;/b&gt;: \" + val[key] + \"&lt;br&gt;\";</code>", "<code>&nbsp;&nbsp;&nbsp;&nbsp;html += \"&lt;b&gt;\" + key + \"&lt;/b&gt;: \" + val[key] + \"&lt;br&gt;\";</code>",
"<code>&nbsp;&nbsp;});</code>", "<code>&nbsp;&nbsp;});</code>",
"<code>&nbsp;&nbsp;html += \"&lt;/div&gt;&lt;br&gt;\";</code>", "<code>&nbsp;&nbsp;html += \"&lt;/div&gt;&lt;br&gt;\";</code>",