Declare an array first:
Copy Code code as follows:
var dictnew=new Array;
var key;
var value;
for (var i = 0; I <50; i++) {
Gets the key value pairs to add to the data dictionary
key= jQuery ("#costCodeIdId" +i). Val ();
Value = Num2zero (JQuery ("#valueId" +i). Val ());
Check whether the key value exists in the data dictionary, and if not, add the key value and value directly to the data dictionary, and if the key value is present, the value is incremented
if (Checkhasindict (key,dictnew)) {
Dictnew[key] = Num2zero (Dictnew[key]) + value;
}else{
Dictnew[key] = value;
}
}
The value of a data dictionary
function Getdictvalue (key,dict) {
var tempdictvalue = "";
For (var k in dict) {
if (K==key) {
Tempdictvalue =dict[k];
return tempdictvalue;
}
}
return tempdictvalue;
}
Check whether the key value exists in the array
function Checkhasindict (key,dict) {
For (var k in dict) {
if (k = = key) {
return true;
}
}
return false;
}