JavaScript implementation-Class dictionary insert or Update method instance _javascript tips

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.