remove value from comma separated values string

前端 未结 9 1821
不知归路
不知归路 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条回答
  •  -上瘾入骨i
    2020-12-30 06:26

    values is now an array. So instead of doing the traversing yourself.

    Do:

    var index = values.indexOf(value);
    if(index >= 0) {
        values.splice(index, 1);
    }
    

    removing a single object from a given index.

    hope this helps

提交回复
热议问题