Replace string with values from two arrays

前端 未结 6 1616
渐次进展
渐次进展 2021-01-16 07:09

I have a string for example:

var string = \'This is a text that needs to change\';

And then I have two arrays.

var array1 =         


        
6条回答
  •  梦毁少年i
    2021-01-16 07:41

    for(var x = 0 ; x < array1.length; x++)
        string = string.replace(new RegExp(array1[x], "g"), array2[x])
    

    FIDDLE

提交回复
热议问题