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 536155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:47:32+00:00 2026-05-13T09:47:32+00:00

I have a little bit of code that looks just like this: function StrippedExample(i1,

  • 0

I have a little bit of code that looks just like this:

function StrippedExample(i1, i2, i3, i4, i5, i6, i7, i8) {
    this.i = [];
    for (var i=1,j=0 ;i<9;i++) {
        var k = eval("i"+i);
        if (k > 0) {
            this.i[j++] = k;
        }
    }
}

FireBug profiler claims that second longest function is eval(), taking up to nearly 6% of the run time.

Everyone says eval is EVIL (as in bad) and slow (as I have found), but I can’t really do anything else – the server simply pulls the data out the database and pushes to the browser.

What alternatives do I have? I could do the same as I am doing here on the server but that just shifts the burden higher up the chain. I can’t change the database layout since everything hooks into those 8 variables and is a massive undertaking.

  • 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-05-13T09:47:32+00:00Added an answer on May 13, 2026 at 9:47 am
    function StrippedExample(i1, i2, i3, i4, i5, i6, i7, i8) {
        var args = [i1, i2, i3, i4, i5, i6, i7, i8]; // put values in an array
        this.i = [];
        for (var i=0,j=0 ;i<8;i++) { // now i goes from 0-7 also
            var k = args[i]; // get values out
            if (k > 0) {
                this.i[j++] = k;
            }
        }
    }
    

    The above code can be simplified further, I just made the minimal change to get rid of eval. You can get rid of j, for example:

    function StrippedExample(i1, i2, i3, i4, i5, i6, i7, i8) {
        var args = [i1, i2, i3, i4, i5, i6, i7, i8];
        this.i = [];
        for (var i = 0; i < args.length; i++) {
            var k = args[i];
            if (k > 0) { this.i.push(k); }
        }
    }
    

    is equivalent. Or, to use the built-in arguments object (to avoid having your parameter list in two places):

    function StrippedExample(i1, i2, i3, i4, i5, i6, i7, i8) {
        this.i = [];
        for (var i = 1; i < arguments.length; i++) {
            var k = arguments[i];
            if (k > 0) { this.i.push(k); }
        }
    }
    

    Even if you weren’t filtering the list, you don’t want to do something like this.i = arguments because arguments is not a real Array; it has a callee property that you don’t need and is missing some array methods that you might need in i. As others have pointed out, if you want to quickly convert the arguments object into an array, you can do so with this expression:

    Array.prototype.slice.call(arguments)
    

    You could use that instead of the var args = [i1, i2 ... lines above.

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

Sidebar

Related Questions

...I'm a little confused, or unsure about how to deal with errors that arise
I have implemented a small method that imports an picture on the iPhone screen,
From ValueType.cs **Action: Our algorithm for returning the hashcode is a little bit complex.
UPDATE 2 This is a known bug/feature with the way Ruby 1.9.2 loads files.
I'm not sure if this kind of question is appropriate, but its been suggested
I know that I should encodeURI any url passed to anything else, because I
I have a manager class with a number of sub-classes. I find one particular
As a programmer my first instinct is to start coding, but then again chapter
Last couple of months I've been wondering about all these password strength meters on
I am trying to create a conditional statement on my dynamic product pages on

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.