First declare an array:
The code copy is as follows:
var dictNew=new Array;
var key;
var value;
for (var i = 0; i <50; i++) {
//Get the key-value pair to be added 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. If it does not exist, add the key value and value to the data dictionary directly. If the key value exists, the value value will be accumulated.
if(checkHasInDict(key,dictNew)){
dictNew[key] = num2zero(dictNew[key]) + value;
}else{
dictNew[key] = value;
}
}
//The value of the 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 ;
}