I have an XML file with texts in a certain language and I need to traverse it and translate certain expressions. I was thinkging about creating an array containing the expressions and an array containing the replacements:
var searchFor = ['Foo', 'Bar'];
var replaceWith = ['Bar', 'Foo'];
Is there some way I can traverse the XML effectively replacing all items in the first array with the next?
xml.each(function(){
$(this).text($(this).text().multiReplace(searchFor, replaceWith));
});
What I'm looking for is a javascript function that is equivalent to the PHP function str_replace that can take in an array for the first and second parameters: http://php.net/manual/en/function.str-replace.php
'FooBar'.multiReplace(searchFor,replaceWith); // should return 'BarFoo'
PS: Alternative solutions are also welcome.