var student = [{
"fname": "Jackie",
"mname": "Lee",
"lname": "Li"
}, {
"fname": "Ken",
"mname": "Ryu",
"lname": "Sha"
}];
for (var i = 0; i < student.length; i++) {
console.log(student[i].fname + " " + student[i].mname + ". " + student[i].lname ? student[i].fname + " " + student[i].mname + ". " + student[i].lname + " , " : " ");
}
I am trying to combine names in the a td these names are from an array. I was able to make the names combine by above code. problem is on the last name there is still a , just want to get rid of the comma when there are no more names that will follow. I am bugged by this simple comma for hours. any idea is appreaciate.
console.log(student[i].fname + " " + student[i].mname + ". " + student[i].lname + ((i < student.length -1) ? ", " : " "));.join()? Fiddle.+=operator. It will make your code easier to parse, errors easier to spot, and solutions easier to find.