javascript - How to Remove last Comma? -
this code generates comma separated string provide list of ids query string of page, there comma @ end of string. how can remove or avoid comma?
<script type="text/javascript"> $(document).ready(function() { $('td.title_listing :checkbox').change(function() { $('#cbselectall').attr('checked', false); }); }); function cotactselected() { var n = $("td.title_listing input:checked"); alert(n.length); var s = ""; n.each(function() { s += $(this).val() + ","; }); window.location = "/d_contactseller.aspx?property=" + s; alert(s); } </script>
use array.join
var s = ""; n.each(function() { s += $(this).val() + ","; });
becomes:
var = []; n.each(function() { a.push($(this).val()); }); var s = a.join(', ');
Comments
Post a Comment