Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ashley Elson
Front End Web Development Techdegree Student 5,972 PointsjQuery .each() & objects question
Hi,
I am currently creating a webpage where it will display League of Legends champion pictures. But I am stuck. This is for to personally get to know how to use loops and object better.
I made this object of some of the champions:
var champions = [
{name: "Aatrox"},
{name: "Ahri"},
{name: "Akali"},
{name: "Alistar"},
{name: "Amumu"},
{name: "Anivia"}
];
And what I am trying to do with this is for each of the names I want to append a list item to my champions unordered list.
This is the jQuery that I have right now
$(document).ready(function() {
$.each(champions, function(key, value) {
console.log(value);
$("#champions").append('<li><img src="http://ddragon.leagueoflegends.com/cdn/6.24.1/img/champion/' + value + '.png"></li>');
});
});
The console.log(value) is giving me in the console "{name: "Aatrox"}" etc.
but how would I just get "Aatrox" instead of {name: "Aatrox"} ?
1 Answer
Ashley Elson
Front End Web Development Techdegree Student 5,972 PointsI managed to figure it out. I was just missing .name at the end of the value. Something so simple but at least I figured it out!