How to remove the last comma of a string in JavaScript?
How to remove the last comma of a string in JavaScript
var contracts ="A,B,C,"
# Removing the last comma
To remove the last comma of a string in JavaScript, we can use the built-in slice() method by passing the 0, -1 as arguments to it.
In the slice() method, negative indexes are used to access the characters from the end of a string.
Here is an example, that removes the last comma from the following string.
contracts =contracts.slice(0, -1)
No comments