How to Remove last Comma?

后端 未结 12 1937
自闭症患者
自闭症患者 2020-12-08 06:58

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

12条回答
  •  悲哀的现实
    2020-12-08 07:48

    Use Array.join

    var s = "";
    n.each(function() {
        s += $(this).val() + ",";
    });
    

    becomes:

    var a = [];
    n.each(function() {
        a.push($(this).val());
    });
    var s = a.join(', ');
    

提交回复
热议问题