The example in this article describes the class dictionary insert or Update method for JavaScript implementations. Share to everyone for your reference. Specifically as follows:
The code expresses the class dictionary inserts or updates the related thought, the interested friend mainly understands the code meaning to be OK, does not need to delve into
<script type= "Text/javascript" > Function insertorupdate (array, KeyName, Keyval, FieldNames, fieldvals) {var ha
sexist = false;
var len = array.length; for (var i = 0; i < len; i++) {if (Array[i][keyname] && array[i][keyname] = = Keyval) {//existing to update ha directly
sexist = true;
for (var j = 0; J < Fieldnames.length J + +) {Array[i][fieldnames[j]] = fieldvals[j];
}} if (!hasexist) {//If not present insert Array[len] = {};
Array[len][keyname] = Keyval;
for (var k = 0; k < fieldnames.length; k++) {array[len][fieldnames[k]] = fieldvals[k];
The var orders = [{"OrderId": 1, "OrderAmount": {"OldValue": Ten, "NewValue": 20}
}, {"OrderId": 2, "OrderAmount": {"OldValue": "," NewValue ": 30}}];
Insertorupdate (Orders, "OrderId", 1, ["OrderAmount"], [{"OldValue": 145, "NewValue": 1125}]);
Console.dir (orders); Insertorupdate (Orders, "OrderId", 3, ["OrderamouNT "], [{" OldValue ":" NewValue ": 95}]);
Console.dir (orders);
</script>
The
wants this article to help you with your JavaScript programming.