Can someone please redirect me to the right link or give an example of how to work with two dimensional array or HashTable in JQuery? I tried google but did not get the answer. I want to avoid using any plugins. All i want to do it, store some information and retrieve them like HashTable way.
有人可以请将我重定向到正确的链接或举例说明如何在JQuery中使用二维数组或HashTable?我试过谷歌但没有得到答案。我想避免使用任何插件。我只想做它,存储一些信息并像HashTable一样检索它们。
3 个解决方案
#1
29
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';
#2
6
two dimensional array is javascript. That's why you are not getting results on google.
二维数组是javascript。这就是为什么你没有在谷歌上获得结果。
it's something like this.
就是这样的。
var arr = [];
arr[0] = [1,12,3,5];
arr[0][0]; // returns 1
arr[0][1]; // returns 12
arr[0][2]; // returns 3
arr[0][3]; // returns 5
or
var outerA = new Array();
outerA[0] = new Array();
outerA[1] = new Array();
outerA[2] = new Array();
#3
0
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.
虽然答案非常晚,但您可以使用jhashtable js库,它几乎模仿java / c#中的hashMap数据结构。它甚至还有一个方法toQueryString(),它将键值对转换为http请求的查询字符串。
#1
29
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';
#2
6
two dimensional array is javascript. That's why you are not getting results on google.
二维数组是javascript。这就是为什么你没有在谷歌上获得结果。
it's something like this.
就是这样的。
var arr = [];
arr[0] = [1,12,3,5];
arr[0][0]; // returns 1
arr[0][1]; // returns 12
arr[0][2]; // returns 3
arr[0][3]; // returns 5
or
var outerA = new Array();
outerA[0] = new Array();
outerA[1] = new Array();
outerA[2] = new Array();
#3
0
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.
虽然答案非常晚,但您可以使用jhashtable js库,它几乎模仿java / c#中的hashMap数据结构。它甚至还有一个方法toQueryString(),它将键值对转换为http请求的查询字符串。