remove value from comma separated values string

前端 未结 9 1830
不知归路
不知归路 2020-12-30 05:27

I have a csv string like this \"1,2,3\" and want to be able to remove a desired value from it.

For example if I want to remove the value: 2, the output string should

9条回答
  •  天命终不由人
    2020-12-30 06:08

    or

    var csv_remove_val = function(s, val, sep) { 
      var sep = sep || ",", a = s.split(sep), val = ""+val, pos;
      while ((pos = a.indexOf(val)) >= 0) a.splice(pos, 1);
      return a.join(sep);
    }
    

提交回复
热议问题