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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:17:15+00:00 2026-05-22T01:17:15+00:00

Due to object in javascript is associative map (HashMap in other programming languages) does

  • 0

Due to object in javascript is associative map (HashMap in other programming languages) does next code

for (var prop in object) {
    if (prop === someConcreteProperty) {
        // some decision
        break;
    }
}

slower anyhow then dummy property lookup like

if (typeof object.someConcreteProperty != 'undefined') {
    // some decision
}

Edits:

I’m thinking about performance in code like:

for ( var prop in obj)
    if (obj[prop] === someAnonymousMethod) {
        // I need that property name for my need
        return obj.prop();
    }

will it be twice property lookup time like

obj.prop()

or more?

Thanks.

  • 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-22T01:17:15+00:00Added an answer on May 22, 2026 at 1:17 am

    This can be tested empirically:

    <script language="javascript">
    
    alert("Initialising test object...");
    var obj = new Object();
    for (var i=0; i<1000000; i++) obj["prop"+i] = i;
    
    
    alert("Initialised. Doing Test.");
    
    var d1 = (new Date()).getTime();
    
    needle = obj["prop"+(i-1)]; // last object
    for (var prop in obj) {
        if (obj === needle) {
            // some decision
            break;
        }
    }
    
    var ms1 = ((new Date()).getTime()) - d1;
    
    alert("Method 1 took "+ms1+"ms.")
    
    var d2 = (new Date()).getTime();
    
    if (typeof obj["prop"+(i-1)] != 'undefined') {
        // some decision
    }
    
    var ms2 = (new Date()).getTime() - d2;
    alert("Method 2 took "+ms2+"ms.")
    
    </script>
    

    Method 1 takes MUCH longer than Method 2. This is hardly surprising since all of the computing necessary to execute Method 2 is included in Method 1 plus MUCH more.

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

Sidebar

Related Questions

Suppose my attempt to write a pickle object out to disk is incomplete due
I have javascript object which consists of complex array of structures with nested structures
I've seen and written many javascript methods like this lately: var myObj = {
I have this code: <script type=text/javascript> $(document).ready(function() { $(#iframeId).contents().find(body).append($(#test)); }); </script> <iframe id=iframeId name=iframeId
i'm getting an error 'Object expected' for some odd reason due to jquery, and
This is a broad-based question around delivering a javascript library that other web developers
I'm trying to create a table-like object within an SVG document. Currently, due to
I was just doing some validation and got some errors due to my javascript...
I have a problem with eventlisteners in javascript that is probably due to my
Due to repetitive errors with one of our Java applications: Engine engine_0: Error in

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.