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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:54:02+00:00 2026-06-18T02:54:02+00:00

My Task In my JavaScript code i’m often using objects to "map" keys to

  • 0

My Task

In my JavaScript code i’m often using objects to "map" keys to values so i can later access them directly through a certain value. For example:

var helloMap = {};
helloMap.de = "Hallo";
helloMap["en"] = "Hello";
helloMap.es = "Hola";

So i build up the map object step by step in my source code using the two available notations object style and array style.

Later i can then access the values i added through helloMap["de"] for example. So thats all fine if i don’t have to care about the order in which the attributes has been set on the object.

If i want to iterate the objects properties now as far as i know there is no way to ensure that i’ll iterate them in the order they have been added (insertion order).

Note: I can’t use some wrapper object and simply hold a array in there and then use its methods to add the values so something like this:

var HelloMap = function(){
  this.myMap = [];
  this.addProperty = function(key, value){
    this.myMap.push({key: key, value: value});
  }
}

or something similar won’t work for me. So the solution needs to be absolutely transparent to the programmer using the object.

That said the object i needed would be an empty object which maintains the order of the properties that were added to it. Something like this would do:

var helloMap = {};
helloMap = getOrderAwareObject(helloMap);

so that every further assignment of the form helloMap.xy = "foo" and helloMap["yz"] = "bar" would be tracked in the object "in order",

Possible Solutions

Since i did not find any solution in underscore or jQuery giving me such a special object i came across the possibility of defining getters and setters for properties in JavaScript objects with Object.defineProperty since i can rely on ECMAScript 5 standard i can use it.

The Problem with this one is, that you have to know all the possible properties that can be set on the object, before they are actually set. Since if you define it you got to name it.

What i am searching for is something like a Default Getter and Default Setter which applies on the object if no getter and setter has been defined for the property. So i could then hide the sorted map behind the object inteface.

  • Is there already a solution for this in any framework you know?
  • Is there a mechanism like "default getter/setter" ?
  • 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-18T02:54:03+00:00Added an answer on June 18, 2026 at 2:54 am

    You’ll need a wrapper of some kind using an array internally, I’m afraid. ECMAScript 5 (which is the standard on which current browser JavaScript implementations are based) simply doesn’t allow for ordered object properties.

    However, ECMAScript 6 will have a Map implementation that has ordered properties. See also http://www.nczonline.net/blog/2012/10/09/ecmascript-6-collections-part-2-maps/.

    There may also be other options in ECMAScript 6. See the following question:

    How can I define a default getter and setter using ECMAScript 5?

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

Sidebar

Related Questions

I'm looking for java framework which can generate javascript code to access backend beans.
I have two JavaScript code snippets. These perform specific task when an 'Update' button
Here is the task: I would like my JavaScript code from different files to
I am attempting to automate the creation of an Outlook Task using JavaScript in
I have acquired the task of updating some horribly outdated JavaScript code which I
I'm quite new to javascript but have undertaken a task to get better aquainted
I know zero javascript, and have one simple task: Find all text in the
I'm creating the following div using javascript, task_id is an int and person_name is
I want to use a scripting language(Javascript, PHP) to achieve the following task. 1)I
Task at hand — I have three versions of some code, developed by different

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.