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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:58:21+00:00 2026-06-07T22:58:21+00:00

I have a JS-hash containing a key length (which represents something completely different than

  • 0

I have a JS-hash containing a key length (which represents something completely different than the length of the hash) and need to iterate over it.

The problem is that jQuery.each is refusing to iterate over this since it detects the length attribute and figures that it must be an array or array-like object.

From the jQuery documentation:

Arrays and array-like objects with a length property (such as a function’s arguments object) > are iterated by numeric index, from 0 to length-1. Other objects are iterated via their
named properties.

This JS fiddle illustrates the problem.

Well, so it’s all documented and understandable. But how to proceed if I just have an attribute named length? Do I have to do a painful renaming before and after iterating the hash, or is there any possibility of telling jQuery to just ignore this property and treat it like any other object attribute?

Thank’s a lot in advance!

  • 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-07T22:58:23+00:00Added an answer on June 7, 2026 at 10:58 pm

    How about not using jquery.each but…

    for (var key in testHash2) {
        if (testHash2.hasOwnProperty(key)) {
            $('#result').append($('<li />').text(key + ':' + testHash2[key]));
        }
    }
    

    UPDATED
    forgot to sanitise the loop with “hasOwnProperty” just in case…

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

Sidebar

Related Questions

I have a url containing a hash e.g http://www.acme.com/home.xsp#key=1234 When the url above loads
I have a rogue gem (omniauth) which provides a hash of data containing ASCII-BIT8
I have a little problem with some hashes. if i have a hash containing,
Hey I have an array where each element is a hash containing a few
I have a hash in which I store the products a customer buys (
I have intialized Hash map inside static block, I need to access the hashmap
Hi I have a hash of hash containing class name, number of students enrolled
Is there a hash implementation around that doens't remember key values? I have to
I wish to have a hash containing references to sub-functions where I can call
I have a hash (in Perl) where the values are all numbers. I need

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.