Replace string with values from two arrays

前端 未结 6 1617
渐次进展
渐次进展 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条回答
  •  粉色の甜心
    2021-01-16 07:50

    Assuming your two arrays have the same size:

    for(var i = 0; i < array1.length; i++){
        mystr = mystr.replace(array1[i], array2[i]);
    }
    

提交回复
热议问题