4

i want to store value like key and value pair in javascript

So far i am doing like this

var list_of_addressbook_entries = {};

list_of_addressbook_entries.guest_name = name ;

for(key in list_of_addressbook_entries)
{
  alert("key " + key
  + " has value "
  + list_of_addressbook_entries[key]);
}

In the above code guest_name is a variable which value is coming from a onclick
so when i am doing the above it showing me the result like

 key guest_name has value M   

it is not printing the value of guest_name

i want the result like

key guest_name_variable value  has key M

Please suggest me what to do here ?

0

1 Answer 1

2

If I've understood right, you need to use the bracket [] syntax, otherwise it is not interpreted as a variable:

list_of_addressbook_entries[guest_name] = name ;

Sign up to request clarification or add additional context in comments.

2 Comments

great one more thing how can i remove a key value pair from the dict ?
delete list_of_addressbook_entries[guest_name];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.