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

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -