LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   In Javascript How to replace elements in one object with elements from another object (https://www.linuxquestions.org/questions/linux-software-2/in-javascript-how-to-replace-elements-in-one-object-with-elements-from-another-object-4175504252/)

pizzipie 05-07-2014 04:20 PM

In Javascript How to replace elements in one object with elements from another object
 
Hi,

This has been driving be nuts!!! I'm trying to replace the names in MySqlRecord with the values in cols.

ie: In MySqlRecord "VendorId": "398" would become "Vendor Id No": "398"
Code:


var cols= {
        "IDno":"Id No",
  "VendorId": "Vendor Id No:",
  "AccountNo": "Account No:"
        }     
 
var MySqlRecord = {
              "IDno": "111",
        "VendorId": "398",
        "AccountNo": "2398-A"
        }

Any help in doing this will be appreciated.

R

j-ray 05-08-2014 03:28 AM

You have to use a third variable (tmp), loop thru the properties of "cols", assign
tmp[cols.property] = MySqlRecord.property;
then
MySqlRecord = tmp;


All times are GMT -5. The time now is 11:47 AM.