As the title suggests I'm trying to remove the last "," that appears when i return my function relative to a specific inputted name: For example I'm getting the following returned: "cat,bird,tiger, " when I'm trying to return "cat,bird,tiger " i have tried string = string.replace(/,\s*$/, ""); but this replaces all commas. here is my current code.
let string = "";
for(let i = 0; i < result.length; i++) {
console.log(result[i].animal)
string = string + result[i].animal + ",";
}
if(string != ""){
console.log(string);
}
else{
console.log("NOT FOUND");
}