Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use replace() with an array[]

Status
Not open for further replies.

jkalb32

Programmer
Apr 2, 2007
5
US
can the replace() method be used with an array globally?, my code is something like
words = words.replace(array[0],stringText)
it works just once but i cannot get it to work on the entire paragraph, how can i attach the g to the array[0]?
 
I think I understand you.

You have to define array[0] as a regular expression.
This will work (tested):

Code:
var thisRegExp = new RegExp(array[0], "g"); 
words = words.replace(thisRegExp, stringText)


[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top