Trim Character In String in JavaScript

Trim is not available built in function in javascript, however regular expression replace can be used.

Replace comma with any other character to trim

<script type="text/javascript">

var str = ',liger, unicorn, snipe,';
var trim = str.replace(/(^\s*,)|(,\s*$)/g, '');

console.log(trim);

</script>