1

I have a hash map I want to use it in javascript. So I thought of converting it into javascript map..how to use it or to do?

1
  • As urgent as it may be, without context it is very difficult to provide useful feedback. There are differences between a Javascript object and a traditional "Map". Can you describe what you intend on storing in the javascript representation and how you intend on referencing the values? Commented Mar 11, 2011 at 2:14

2 Answers 2

6

Turn it into an object literal...

var map = {
   'a' : 'a',
   'b': 'b'
   ...
};
Sign up to request clarification or add additional context in comments.

Comments

0

Or use Associative Arrays, for example:

var arr = new Array();
arr["One"] = 1;
arr["Two"] = 2;
arr["Thr"] = 3;
arr["For"] = 4;

for(var i in arr)
{
    alert('Key='+i + ', Value = '+arr[i]);     
}

2 Comments

There are no associative arrays in ECMAScript.
Your code works because Arrays are also objects. You shouldn't use arrays in this manner.

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.