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

  • Home
  • SEARCH
  • 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 9238409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:45:20+00:00 2026-06-18T07:45:20+00:00

I am writing a greasemonkey script and using an external script that creates a

  • 0

I am writing a greasemonkey script and using an external script that creates a preferences window. The preferences window is initialized with the following code:

USP.init({
        theName: 'show_advd',
        theDefault: true
    }, {
        theName: 'show_ahd',
        theDefault: true
    }, {
        theName: 'show_at',
        theDefault: true
    }, {
        theName: 'show_bithd',
        theDefault: true
    }, {
        theName: 'show_bmtv',
        theDefault: true
    });

The code is actually about 50 of those blocks instead of just 5, and it is constantly being updated. What I want to do is have an external file of the names that would be read in and made into an array. For test purposes I’m just using a test array.

var test = ['test0','test1','test2'];

Now I was planning on using a for loop to make the block so I would have just one instead of 50, but I can’t figure out how to not break the formatting that’s necessary.

It would look something like this:

USP.init(
for(int i=0;i<test.length;i++)
{
    {
        theName: test[i],
        theDefault: true
    }
});

But obviously that doesn’t work. Thoughts on a workaround?

  • 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-18T07:45:21+00:00Added an answer on June 18, 2026 at 7:45 am

    You can’t include a for-loop like that because it is a statement and does not evaluate to an expression. You can only have expressions as arguments to a function, and the {...} terms here are object literals, which are just expressions that evaluate to an object.

    What you need to do is create an array with your for-loop and pass that in to your function using Function.apply.

    Here is an example:

    var args = [];
    
    for (var i = 0; i < test.length; i++) {
      args.push({
        theName    : test[i],
        theDefault : true
      });
    }
    
    USP.init.apply(USP, args)
    

    The apply method takes two arguments. The first one is the value of this inside the function; it has to be the object you want to call the function on. The second argument is an array, it will be passed into the function as its arguments.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a greasemonkey script that is parsing a page with the following
I'm writing a greasemonkey script that creates an auto-complete search type box which makes
I'm writing a Greasemonkey script that has a fair few user settings (just using
I am writing a greasemonkey script. The site is using jquery, i need a
I'm writing a GreaseMonkey script that modifies an attribute of an element with a
Background : I'm currently writing a greasemonkey script that embeds/modifies a specific page's html.
I am writing a simple GreaseMonkey script that has a jQuery plugin called hoverIntent
I am writing a fairly basic GreaseMonkey script that locates text in a specific
I am writing a Greasemonkey script using jquery, and I want to add information
I'm writing a Greasemonkey script that I'm trying to use in Chrome and Firefox.

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.