This code generates a comma separated string to provide a list of ids to the query string of another page, but there is an extra comma at the end of the string. How can I re
Write a javascript function :
var removeLastChar = function(value, char){ var lastChar = value.slice(-1); if(lastChar == char) { value = value.slice(0, -1); } return value; }
Use it like this:
var nums = '1,2,3,4,5,6,'; var result = removeLastChar(nums, ','); console.log(result);
jsfiddle demo