Created
April 23, 2016 17:04
-
-
Save joechan3/d4eedfbd0700c8b7a6c2ab73e894c859 to your computer and use it in GitHub Desktop.
Looping through JavaScript objects From: Lynda - JavaScript and JSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<title>JavaScript And JSON</title> | |
</head> | |
<body> | |
<h2>Links</h2> | |
<ul id="links"> | |
</ul> | |
<script> | |
var info = { | |
"full_name" : "Ray Villalobos", | |
"title" : "Staff Author", | |
"links" : { | |
"blog" : "http://iviewsource.com", | |
"facebook" : "http://facebook.com/iviewsource", | |
"youtube" : "http://www.youtube.com/planetoftheweb", | |
"podcast" : "http://feeds.feedburner.com/authoredcontent", | |
"twitter" : "http://twitter.com/planetoftheweb" | |
} | |
}; | |
var output = ""; | |
for ( key in info.links ) { | |
if (info.links.hasOwnProperty(key)) { | |
output += '<li>' + | |
'<a href = "' + info.links[key] + | |
'">' + key + '</a>' + | |
'</li>'; | |
} //if the links has the key property | |
} // for...go through each link | |
var update = document.getElementById('links'); | |
update.innerHTML = output; | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment