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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:22:58+00:00 2026-06-07T08:22:58+00:00

I have a question about Javascript’s dictionary. I have a dictionary in which key-value

  • 0

I have a question about Javascript’s dictionary. I have a dictionary in which key-value pairs are added dynamically like this:

var Dict = []
var addpair = function (mykey , myvalue) [
  Dict.push({
    key:   mykey,
    value: myvalue
  });
}

I will call this function and pass it different keys and values. But now I want to retrieve my value based on the key but I am unable to do so. Can anyone tell me the correct way?

var givevalue = function (my_key) {
  return Dict["'" +my_key +"'"]         // not working
  return Dict["'" +my_key +"'"].value // not working
}

As my key is a variable, I can’t use Dict.my_key

Thanks.

  • 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-07T08:23:02+00:00Added an answer on June 7, 2026 at 8:23 am

    Arrays in JavaScript don’t use strings as keys. You will probably find that the value is there, but the key is an integer.

    If you make Dict into an object, this will work:

    var dict = {};
    var addPair = function (myKey, myValue) {
        dict[myKey] = myValue;
    };
    var giveValue = function (myKey) {
        return dict[myKey];
    };
    

    The myKey variable is already a string, so you don’t need more quotes.

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

Sidebar

Related Questions

I have a conceptual question about photo galleries like this: http://www.nikesh.me/demo/image-hover.html If you open
My question is about Javascript. I have a Callback function which receives a Position
I am making a webapp. I have a fairly basic question about javascript performance.
I have been learning the Definitive Guide of JavaScript.i got a question about the
I have a general question about the design of JavaScript Libraries. I am trying
I have a question about Javascript widgets. The widget I am working on simply
I have a question about javascript time ranges i have two input boxes, the
I have a question about the javascript. I write a function in the javascript
i have a question about google maps markers and javascript. i have a page
I have an instrestion question about boolean logiс in javascript. I have a FOR

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.