Bad code in a Waypoint snippet #4434
Replaced .map() method with .forEach()
This commit is contained in:
@ -160,14 +160,14 @@
|
||||
"title": "Convert JSON Data to HTML",
|
||||
"description": [
|
||||
"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>.",
|
||||
"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:",
|
||||
"<code>json.map(function(val) {</code>",
|
||||
"<code>json.forEach(function(val) {</code>",
|
||||
"<code> var keys = Object.keys(val);</code>",
|
||||
"<code> html += \"<div class = 'cat'>\";</code>",
|
||||
"<code> keys.map(function(key) {</code>",
|
||||
"<code> keys.forEach(function(key) {</code>",
|
||||
"<code> html += \"<b>\" + key + \"</b>: \" + val[key] + \"<br>\";</code>",
|
||||
"<code> });</code>",
|
||||
"<code> html += \"</div><br>\";</code>",
|
||||
|
Reference in New Issue
Block a user