Does jQuery support a set of dictionaries (key, value)?

Does jQuery support the Dictionaries collection (key, value)?

I would like to set the following data in the structure

 [1, false] [2, true] [3, false] 

with the ability to add, search, delete and update.

Any help!

+48
javascript jquery collections dictionary
Mar 23 '11 at 7:44
source share
5 answers

No, jQuery is not, but Javascript does.

Just use the object:

 var dict = { "1" : false, "2" : true, "3" : false }; // lookup: var second = dict["2"]; // update: dict["2"] = false; // add: dict["4"] = true; // delete: delete dict["2"]; 
+99
Mar 23 '11 at 7:50
source share

jQuery, no. But JavaScript does. JavaScript has only two structures: arrays and objects .

Objects can be used as a dictionary, where the properties are "keys":

 var dict = { 1: true, 2: true, 3: false }; 

Object properties can either be obtained using dot notation, obj.property (if the property name is a valid identifier that uses a digit, as indicated above, or with an array access record, obj['property'] .

+5
Mar 23 '11 at 7:50
source share

With pure JavaScript,

 var myDictionary = new Object(); myDictionary[1] = false; myDictionary[2] = true; myDictionary[3] = false; function look(i) { return myDictionary[i];} look(1); // will return false 
+3
Mar 23 '11 at 7:50
source share

Yes, you can use an object for this:

 var myDict = { 1:false , 2:true , 3:false }; 
+2
Mar 23 2018-11-11T00:
source share

You do not need separate dictionary classes, because Javascript objects act like dictionaries. See this:

 var userObject = {}; // equivalent to new Object() userObject["lastLoginTime"] = new Date(); alert(userObject["lastLoginTime"]); 

Full article here: http://msdn.microsoft.com/en-us/magazine/cc163419.aspx

+2
Mar 23 2018-11-11T00:
source share



All Articles