Remove all occurrences except last?

后端 未结 9 1584
深忆病人
深忆病人 2020-12-03 07:06

I want to remove all occurrences of substring = . in a string except the last one.

E.G:

1.2.3.4

should become:

9条回答
  •  感动是毒
    2020-12-03 07:42

    var s='1.2.3.4';

    s=s.split('.');
    s.splice(s.length-1,0,'.');
    s.join('');
    

    123.4

提交回复
热议问题