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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:53:22+00:00 2026-06-11T07:53:22+00:00

Consider the following article explaining hashtables / dictionaries in JavaScript: Can anyone recommend a

  • 0

Consider the following article explaining hashtables / dictionaries in JavaScript:

Can anyone recommend a good Hashtable implementation in Javascript?

Given the accepted answer, I want to be able to do this:

var instance = new Dictionary();
instance['key1'] = 'Foo';
instance['key2'] = 'Bar';
instance['key3'] = 123;
instance['key4'] = true;

but I want the key/value pairs to point to an object within the Dictionary internally. consider the following code structure

var Dictionary = function() {
    var dictionary; // <-- key value pairs should point to this, not to the Dictionary function;

    this.setValue = function(key, value) {
        dictionary[key] = value;
    }

    this.getValue = function() {
        return dictionary[key];
    }
}

Is this possible?

EDIT:

One way I thought of designing the Dictionary object was like so:

var Dictionary = function() {
    this.setValue = function(key, value) {
        this[key] = value;  
    }

    this.getValue = function(key) {
        return this[key];
    }
}

The problems with this are:

  1. I can assign like so instance[‘key1’] = ‘foo’; and read like this instance.key1; I don’t want this!!

  2. I can assign this instance[‘getValue’] = null; and then cannot get a value back because the function is now null!!

Neither of the above should occurr, hence the reason that the set and get functionality should apply to the internal object, not to the dictionary itself.

  • 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-11T07:53:24+00:00Added an answer on June 11, 2026 at 7:53 am
    function Dictionary()
    {
        this.store = {};    
        this.setValue = function(key, value) {
            store[key] = value;
        }
        this.getValue = function(key)
        {
            return store[key];
        }
        return this;
    }
    //Testing
    var dict = Dictionary();
    dict.setValue('key','value');
    alert(dict.getValue('key'));//displays "value"
    alert(dict.getValue('unassignedKey'));//displays "undefined"
    alert(dict['key']);//displays "undefined" (an unfortunate lack of syntactic convenience, we have to go through getValue).
    alert(dict.key);//displays "undefined"
    var dict2 = Dictionary();
    dict2.setValue('key2', 'value2');
    alert(dict2.getValue('key'));//displays "undefined"
    alert(dict2.getValue('key2'));//displays "value2"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider following code: My problem is: 1) I can't seem to cast the errors
Consider following two tables: tag_names (tag_id, tag_name) tag_links (tag_id, image_id) An image can have
I can't figure this out, consider the following code: <ListBox Width=200 ItemsSource={Binding CurrentArticle.ArticleCategories} DisplayMemberPath={Binding
Consider the following piece of code: public class Article : AbstractEntity<Article> { // ...
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider following make: all: a b a: echo a exit 1 b: echo b
Consider following string Some string with quotes and \pre-slashed\ quotes Using regex, I want
Consider following text: $content=<<<EOT { translatorID: f4a5876a-3e53-40e2-9032-d99a30d7a6fc, label: ACL, creator: Nathan Schneider, target: ^https?://(www[.])?aclweb\\.org/anthology-new/[^#]+,
Consider following 2 programs giving same error First calss: public class Testing { Testing
consider following: 1st APPROACH: public void f3() { f2(); f1(); } and this ...

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.