I have an API call going on which returns the venue_capacity
of a soccer team as a number without thousand separator. I would like to print this as string and thousand separator included.
My idea is to run the function after I have the data from the API to manipulate the variable venue_capacity
accordingly.
This is my current attempt (from this thread: How to print a number with commas as thousands separators in JavaScript) which returns the figure without a separator:
$.ajax({
method: "GET",
async: "True",
dataType: "json",
url: "https://cors-anywhere.herokuapp.com/https://www.api-football.com/demo/api/v2/teams/team/" + team_id,
success: function(response) {
var team_info = response;
console.log(team_info);
team = team_info.api.teams[0].name;
founded = team_info.api.teams[0].founded;
venue_capacity = team_info.api.teams[0].venue_capacity;
function numberWithCommas(venue_capacity) {
return venue_capacity.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
$("#selectedClub").html(team);
$("#founded").html(founded);
$("#venue_capacity").html(venue_capacity);
}