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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:20:23+00:00 2026-05-24T06:20:23+00:00

I know in JavaScript, objects double as hashes, but I have been unable to

  • 0

I know in JavaScript, objects double as hashes, but I have been unable to find a built-in function to get the keys:

var h = {a:'b', c:'d'};

I want something like

var k = h.keys() ; // k = ['a', 'c'];

It is simple to write a function myself to iterate over the items and add the keys to an array that I return, but is there a standard cleaner way to do that?

I keep feeling it must be a simple built in function that I missed but I can’t find 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-24T06:20:24+00:00Added an answer on May 24, 2026 at 6:20 am

    There is function in modern JavaScript (ECMAScript 5) called Object.keys performing this operation:

    var obj = { "a" : 1, "b" : 2, "c" : 3};
    alert(Object.keys(obj)); // will output ["a", "b", "c"]
    

    Compatibility details can be found here.

    On the Mozilla site there is also a snippet for backward compatibility:

    if(!Object.keys) Object.keys = function(o){
       if (o !== Object(o))
          throw new TypeError('Object.keys called on non-object');
       var ret=[],p;
       for(p in o) if(Object.prototype.hasOwnProperty.call(o,p)) ret.push(p);
       return ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Yes, I know you could use regular objects as associative arrays in JavaScript, but
I know zero javascript, and have one simple task: Find all text in the
I'm setting up my javascript objects like the following Object1 = function() { var
I have a line in a javascript function that sort an array of objects
Where can I find a good list and description of Javascript built-in objects? I
I know that the prototype property of JavaScript function objects is copied to the
I have an array of objects in javascript and I know that I need
I have this function to sort a JavaScript array of objects based on a
I know Javascript always passes objects by reference. But what about the other types?
I know we can create new properties in Javascript objects during runtime but could

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.