I have a function writen in ajax that return a set of value:
$.each(data.dataa, function (i,item) {
$.each(item, function (index, dat) {
$str+=dat;
})
$ulSub.append( '<li id="'+item.id +'" class="ui-widget-content">' +$str+'</li>');
});
Each item has two attribute: the id and the lastname,
the value of each $str is a concatenation of the id and the lastname, but I want just the lastname not the id. I used the function item[2] but it's not working.
the result of my code is shwon as follow
What I want is just get the value of the lasname. I know that I should use item.lastname, but I want to ask if there are other methods to get the value of the lastname because the second attribute (lastname) is a variable.


$.each(item, check ifindexis the target variable's name, if it is, append thedatto the$str. Orvar target = 'lastname'; //whatever it is., then$str += item[target];