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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:34:30+00:00 2026-05-25T01:34:30+00:00

I need to make a Javascript object that would behave as an associative array,

  • 0

I need to make a Javascript object that would behave as an associative array, but with some functions that are called before getting and setting properties.

For example, the task may be like this: we should make an object, that would contain a squared value of a key, like this:

obj.two should be equal to 4, 
obj.four should be equal to 16, 
obj['twenty one'] should be equal to 441.

This is an example. Actually I need to make setting operation overridden too. The getting and setting operations would go to the database, and they not necceserily would take strings as keys, but any types of objects, from which it would create a DB query.

How would I do that a) with as less thirdparty libraries as possible and b) to make it work on as much platforms as possible?

I am new to JS, I’ve found that JS has no associative arrays, relying on the ability to define objects on the fly with arbitrary properties. I googled and had an idea to use or even override lookupgetter (and setter), where define a new getter/setter on the fly, but I coundn’t find if the interpreter would use this method every time it encounters new key. Anyway, it looks like I wouldn’t be able to use anything except strings or maybe numbers as keys.

In Java, I would just implement java.util.Map.

Please help me, how would I do the same in Javascript?

edit

I think I will get what I want if I manage to override [[Get]] and [[Put]] methods mentioned here http://interglacial.com/javascript_spec/a-8.html#a-8.6.2.1

  • 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-25T01:34:31+00:00Added an answer on May 25, 2026 at 1:34 am

    I decided that the most correct way to implement this is to use Harmony:Proxies. It isn’t working on all platforms, but it lets implement this in the most seamless way; and it may be supported in more platforms in the future.

    This page contains an example that I used as a template to do what I want:

    http://wiki.ecmascript.org/doku.php?id=harmony:proxies

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

Sidebar

Related Questions

I want to make a custom Array object that recieves a number as index,
I need to make a WebCast presentation soon and need to do some whiteboarding
I need to make sure that user can run only one instance of my
I need to make some reflective method calls in Java. Those calls will include
I need to make a form that can display certain form inputs when another
I would like to be able to make an application that uses open layers
I have the following javascript which I need to make dynamic. data.addRows(2); data.setValue(0, 0,
i have a input tag which is non editable, but some times i need
I’m making a JavaScript object with literal notation, but I’m not sure how to
I have a crystal report file I need make a tiny edit in. It

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.