This question has already been answered:
First, the values from the JSON array were "pulled out" by variables:
var login = data.login, name = data.name, avatar_url = data.avatar_url, bio = data.bio; and placed in HTML using javascript:
$('#avatar').html(''); var avatarImg = '<img src=' + avatar_url + ' class="img-circle" >'; $('#avatar').append(avatarImg); $('#name').html(''); var name = '<span>' + name + '</span>'; $('#name').append(name); $('#login').html(''); var login = '<span>' + login + '</span>'; $('#login').append(login); $('#bio').html(''); if (bio == null) { var bio = '<a href="#">Add a bio</a>'; }else { var bio = '<p>' + bio + '</p>' } Everything works fine, but for optimization I wanted to use a function that would pull the value from data and put this value where it needed. For example:
var templ = function (item) { var itemId = '#' + item; var itemData = data.item; $(itemId).html(''); var itemTypeTempl = '<span>' + itemData + '</span>'; $(itemId).append(itemTypeTempl); }; templ('login'); But var itemData = data.item does not return data.login as I would like. Tried var itemData = 'data.' + item var itemData = 'data.' + item - but returns the string "data.login" , and I need to pull the data.