I have two arrays.
var a = ['one', 'two', 'three'];
var b = ['two', 'three', 'four'];
var string = 'The only one and two and three';
I tried to use for-loop.
for ( var i = 0; i < string.length; i++) {
string = string.replace(a[0], b[0]);
string = string.replace(a[1], b[1]);
string = string.replace(a[2], b[2]);
}
But the problem is that after first iteration replaced value replaces again! I want to replace one with two, two with three and three with four.
Expected result: The only two and three and four
I get: The only four and four and four
i < string.length? I think, It should bea.lengthorb.length.