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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:53:57+00:00 2026-05-12T14:53:57+00:00

This is so simple I am baffled. I have the following: var x =

  • 0

This is so simple I am baffled. I have the following:

var x = 'shrimp';    
var stypes = new Array('shrimp', 'crabs', 'oysters', 'fin_fish', 'crawfish', 'alligator');
for (t in stypes) {
    if (stypes[t] != x) {
        alert(stypes[t]);
    }
}

Once the values have iterated it starts returning a dozen functions like

function (iterator, context) {
    var index = 0;
    iterator = iterator.bind(context);
    try {
        this._each(function (value) {iterator(value, index++);});
    } catch (e) {
        if (e != $break) {
            throw e;
        }
    }
    return this;
}

What the heck is going on?

Edit: In these scripts I am using http://script.aculo.us/prototype.js and http://script.aculo.us/scriptaculous.js I remember now reading about the way prototype extends arrays and I am betting this is part of it. How do I deal with it?

  • 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-12T14:53:57+00:00Added an answer on May 12, 2026 at 2:53 pm

    The for enumeration is going to go over every member of the object you passed it. In this case an array, which happens to have functions as members as well as the elements passed.

    You could re-write your for loop to check if typeof stypes[t] == "function" or yada yada. But IMO you are better off just modifying your looping to only elements..

    for(var i = 0, t; t = stypes[i]; ++i){
        if (t != x) {
            alert(t);
        }
    }
    

    Or

    for(var i = 0; i < stypes.length; ++i){
        if (stypes[i] != x) {
            alert(stypes[i]);
        }
    }
    

    I wanted to migrate my last comment up to the answer to add the notice of the a caveat for the first type of loop.

    from Simon Willison’s “A re-introduction to JavaScript”..

    for (var i = 0, item; item = a[i]; i++) {
        // Do something with item
    }
    

    Here we are setting up two variables.
    The assignment in the middle part of
    the for loop is also tested for
    truthfulness – if it succeeds, the
    loop continues. Since i is incremented
    each time, items from the array will
    be assigned to item in sequential
    order. The loop stops when a “falsy”
    item is found (such as undefined).

    Note that this trick should only be
    used for arrays which you know do not
    contain “falsy” values (arrays of
    objects or DOM nodes for example). If
    you are iterating over numeric data
    that might include a 0 or string data
    that might include the empty string
    you should use the i, j idiom instead.

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

Sidebar

Related Questions

I have the following code with a simple class and a method for writing
I've done extensive research on this, and am baffled. Similar questions on stackoverflow have
This simple code show you the problem: class MyObject { var $publicString = This
This simple problem reoccurs many times for me in .NET with WinForms. I have
I am baffled by this simple task i do over and over again. I
This is probably simple but I am new at jQuery so... In IE 8
This simple code: [HttpPost] public ActionResult Check(string chosen_username, string email) { var lang =
This simple code is not producing any sound on a couple of machines that
This simple example fails to compile in VS2K8: io_service io2; shared_ptr<asio::deadline_timer> dt(make_shared<asio::deadline_timer>(io2, posix_time::seconds(20))); As
This simple regex matching returns a string instead of an object on every browser

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.