Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:56:39+00:00 2026-06-12T11:56:39+00:00

I have the following that is iterating over an array of templateOverrides. DPGlobal.template is

  • 0

I have the following that is iterating over an array of “templateOverrides”. DPGlobal.template is the original template which I need to override. My issue is that I need to pass the g flag to the .replace() method on the var newTemplate = ... line. It’s working insofar as I am able to dynamically iterate through and override template pieces one at a time, but the g flag is not passed. I’m mainly curious what is the most DRY method of achieving it…

for ( var i in templateOverrides ) {
    var thisOverride = templateOverrides[i];
    var origGlobalTemplate = DPGlobal[thisOverride];
    var newTemplate = DPGlobal.template.replace(origGlobalTemplate, options[thisOverride]);
    DPGlobal.template = newTemplate;
    i++;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:56:41+00:00Added an answer on June 12, 2026 at 11:56 am

    If you declare it via new RegExp(), you can then include the /g modifier as the second parameter to the constructor

    var newTemplate = DPGlobal.template.replace(new RegExp(origGlobalTemplate,'g'), options[thisOverride]);
    

    By the way, is templateOverrides really an Array [], or is it an object {}? If it is an Array, you ought to be using an incremental for loop rather the for-in construct, whose purpose is iterating over object properties.

    for ( var i=0; i<templateOverrides.length; i++ ) {
      var thisOverride = templateOverrides[i];
      var origGlobalTemplate = DPGlobal[thisOverride];
      var newTemplate = DPGlobal.template.replace(new RegExp(origGlobalTemplate,'g'), options[thisOverride]);
      DPGlobal.template = newTemplate;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following is a method that is iterating over a list: @Override public void DataRowMapper(List<?>
I have the following method that returns void and I need to use it
I'm iterating over a 3 dimensional array (which is an image with 3 values
In my testing, I have noticed that iterating over tied arrays are at best
I have an application that iterates over an array every step and I seem
I have following script that executes all the .reg files in the current directory.
I have following code that I am compiling in a .NET 4.0 project namespace
I have following code that does not work due to a being a value
I have following code that does not work: I never get to goToFoodDetail .
I have the following that I retreive the title of each url from an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.