-
Search and replace item in array ?
Probably there is a better way to do it:
I am trying to replace all the instances of a specific font in an array :This method is working to find “Roboto” and replace it with “Open Sans”
toSort = [“Verdana”, “Roboto”, “Times New Roman”, “Verdana”, “Roboto”];
var str = toSort.toString();
var patt1 = /Roboto/;
var result = str .replace(str.match(patt1), “Open Sans”);
alert(result);Whan I try to search globally (var patt1 = /Roboto/g;) it’s not working at all (not finding “Roboto” at all );
My final goal is to set the search word and the replace word as array elements :
this is not successful at all for me :Thank you for any help or idea
toSort = ["Verdana","Roboto","Times New Roman","Verdana", "Roboto"];
desFont = ["Exo2","Open Sans"];var str = toSort.toString();
var src = toSort[0].toString();
var rplc = desFont[0].toString();var patt1 = /src*/g;
var result = str .replace((str.match(patt1)), rplc);
alert( result);
Sorry, there were no replies found.