I am trying to loop over my array called topics. This array has names of people. Within my loop, i want to grab each name and plug it into a button with its text.
When i console.log my loop, i can see each name in my array get printed. But when i try to append the text of my buttons, it only adds the last name in my array.
var topics = ["Lebron James", "Kevin Durant", "Steph Curry", "James Harden", "Russel Westbrook", "Giannis Antetokounmpo", "Kawhi leonard", "Anthony Davis", "Paul George", "Kyrie Irving"];
for (var i = 0; i < topics.length; i++) {
$(".gifnames").append("<button type=\"button\" class=\"btn btn-primary\">");
$("button").text(topics[i]);
console.log(topics[i]);
}
only Kyrie irvings name is added to all buttons instead of each name being added to the buttons created.