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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:46:28+00:00 2026-05-23T02:46:28+00:00

The Object.keys() method works fine for me with code like this: var foo =

  • 0

The Object.keys() method works fine for me with code like this:

var foo = {foo: 1, bar: 2};
console.log(Object.keys(foo).length);

However, Object.keys() returns a zero-length array for built-in objects with code like this:

<!doctype html> 
<html>

<head>

<title>Object.keys()</title>

</head>

<body>
<script type="text/javascript">
console.log(Object.keys(window.document).length);
</script>

</body>

</html>

Am I missing something? I’m using Internet Explorer 9.0.8112.16421.


Postscript: I’m still not clear why this (for example):

    for (prop in performance.timing) {
        if (performance.timing.hasOwnProperty(prop)) {
            console.log(prop); 
        }
    }

…produces nothing in IE9, whereas this works fine:

for (prop in performance.timing) {
    console.log(prop); 
}
  • 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-23T02:46:29+00:00Added an answer on May 23, 2026 at 2:46 am

    In JavaScript, there are native objects and host objects. In general, you can rely on things like Object.keys working with native objects, but not with host objects. window, document, and others are host objects. IE in particular is well-known for its host objects not being native-like (host functions don’t have the call or apply feature, etc.).

    Alternately, of course, it could be that document has no enumerable properties. Most of the default properties of objects are non-enumerable and so don’t show up in Object.keys. For instance, Object.keys([]).length and Object.keys(new RegExp(".*")).length are both 0 because neither has any enumerable properties even though they both have lots of properties (they have properties for all of their “methods”, and of course the blank array has a length property and the RegExp has a lastIndex property).


    Update: And in fact, it was the enumerable thing. Try this test:

    alert(Object.keys(window.document).length);
    window.document.AAA__expando__property = "foo";
    alert(Object.keys(window.document).length);
    

    For me, on IE9, those alerts are “0” and “1”, respectively. So window.document supports Object.keys, it’s just that window.document doesn’t, by default, have any enumerable properties. (In contrast, on Chrome I get 65 enumerable properties to start with, and of course 66 once I’ve added my expando.)

    Here’s a rather more full test page (live copy) (hacked-together quickly, not a thing of beauty):

    window.onload = function() {
    
      document.getElementById('theButton').onclick = function() {
    
        if (typeof Object.keys !== 'function') {
          display("<code>Object.keys</code> is not a function");
          return;
        }
        showKeys("Before adding", Object.keys(window.document));
        window.document.AAAA__expando__foo = "bar";
        showKeys("After adding", Object.keys(window.document));
      };
    
      function showKeys(prefix, keys) {
        var p, ul;
    
        keys.sort();
        prefix =
          "[" + prefix +
          "] Keys on <code>window.document</code> (" +
          keys.length +
          ")";
        if (keys.length !== 0) {
          prefix += " (click to toggle list)";
        }
        p = display(prefix);
        if (keys.length !== 0) {
          ul = document.createElement("ul");
          ul.innerHTML = "<li>" + keys.join("</li><li>") + "</li>";
          ul.style.display = "none";
          document.body.appendChild(ul);
          p.onclick = function() {
            ul.style.display =
              (ul.style.display === "none") ? "" : "none";
          };
        }
      }
    
      function display(msg) {
        var p = document.createElement('p');
        p.innerHTML = msg;
        document.body.appendChild(p);
        return p;
      }
    
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The MSDN documentation on Object.GetHashCode() describes 3 contradicting rules for how the method should
I want to build a method which accepts a string param, and an object
Has anyone else run into this problem before? I've got a method that calls
I am trying to insert about 50,000 objects (and therefore 50,000 keys) into a
Object o = new Long[0] System.out.println( o.getClass().isArray() ) System.out.println( o.getClass().getName() ) Class ofArray =
Object-relational mapping has been well discussed, including on here. I have experience with a
Object-databases are used very seldomly, albeit they offer a way to live without SQL,
What object do you query against to select all the table names in a
Since Object Initializers are very similar to JSON, and now there are Anonymous Types
The object I’m working on is instantiated in JavaScript, but used in VBScript. 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.