How To - Store Key Value Pair in Two Dimensional Array and HashTable using JQuery? How To - Store Key Value Pair in Two Dimensional Array and HashTable using JQuery? jquery jquery

How To - Store Key Value Pair in Two Dimensional Array and HashTable using JQuery?


Depending on what you want to use as keys into your "hashtable", you might want to use an object with array properties instead of a two dimensional array.

For instance:

var hashtable = {};hashtable['screaming'] = ["red","orange"];hashtable['mellow'] = ["skyblue","yellow","green"];

you can also set and access values in an object using dot notation:

hashtable.screaming = ["red","orange"];alert(hashtable.screaming[0]);

If you're just looking to keep track of key/value pairs then an object is the way to go:

var hashtable = {};hashtable['key1'] = 'value1';hashtable['key2'] = 'value2';hashtable.key3 = 'value3';


two dimensional array is javascript. That's why you are not getting results on google.

it's something like this.

var arr = [];arr[0] = [1,12,3,5];arr[0][0]; // returns 1arr[0][1]; // returns 12arr[0][2]; // returns 3arr[0][3]; // returns 5

or

var outerA = new Array();outerA[0] = new Array();outerA[1] = new Array();outerA[2] = new Array();


Although a very late answer , you can use jhashtable js library which almost mimics hashMap datastructure in java/c#.It even has a method toQueryString() which converts the key-value pair to querystring for http requests.

http://www.timdown.co.uk/jshashtable/index.html