[removed] replace last occurrence of text in a string

后端 未结 14 784
一整个雨季
一整个雨季 2020-12-02 18:13

See my code snippet below:

var list = [\'one\', \'two\', \'three\', \'four\'];
var str = \'one two, one three, one four, one\';
for ( var i = 0; i < list.         


        
14条回答
  •  既然无缘
    2020-12-02 18:36

    I would suggest using the replace-last npm package.

    var str = 'one two, one three, one four, one';
    var result = replaceLast(str, 'one', 'finish');
    console.log(result);

    This works for string and regex replacements.

提交回复
热议问题