OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Merge two Object and create new one [duplicate]

  • Thread starter Thread starter Nitin
  • Start date Start date
N

Nitin

Guest
I have two objects and require to merge those and create a new One.

Both has "serviceId" and "properties".

Code:
var user = {
  "presentForUser": [{
    "serviceId": "useradmin",
    "properties": []
  }, {
    "serviceId": "enett",
    "properties": [{
      "mailbox": ["mybox"]
    }, {
      "b2bcid": ["TEST12345"]
    }]
  }, {
    "serviceId": "portal-kar-restricted",
    "properties": [{
      "ssn-concession": ["Ja"]
    }, {
      "account": ["ashasjkdhasjkhd"]
    }]
  }]
}

Code:
var company = {
  "presentForCompany": [{
    "serviceId": "useradmin",
    "properties": []
  }, {
    "serviceId": "invoice-archive",
    "properties": []
  }, {
    "serviceId": "enett",
    "properties": [{
      "mailbox": ["mybox", "testBox"]
    }, {
      "b2bcid": ["TEST12345"]
    }]
  }, {
    "serviceId": "transhist",
    "properties": []
  }, {
    "serviceId": "BS-Arkiv",
    "properties": []
  }, {
    "serviceId": "sepaonline-dt2",
    "properties": []
  }, {
    "serviceId": "sepaonline-ncb",
    "properties": []
  }, {
    "serviceId": "sepaonline-pbs",
    "properties": []
  }, {
    "serviceId": "BS-web",
    "properties": []
  }, {
    "serviceId": "ClearingDBABankReg",
    "properties": []
  }, {
    "serviceId": "BS-Creditor",
    "properties": []
  }, {
    "serviceId": "portal-kar-restricted",
    "properties": [{
      "ssn-concession": ["Ja"]
    }, {
      "account": ["ashasjkdhasjkhd"]
    }]
  }, {
    "serviceId": "Sepa-Customer-Service",
    "properties": []
  }, {
    "serviceId": "examples",
    "properties": [{
      "access": ["A", "B", "C", "D", "E"]
    }]
  }, {
    "serviceId": "hobo",
    "properties": [{
      "role": ["admin", "exela_admin_superuser", "exela_standard_role_1", "exela_standard_role_2", "exela_superuser"]
    }]
  }, {
    "serviceId": "peppol-kportal",
    "properties": [{
      "role": ["ROLE_PEPPOL_KPORTAL"]
    }]
  }]
}

I need to compare both the object based on "serviceId" and create a check box for values available inside "mailbox" or "account"(just an example) and keep the common values (from both the object) checked and values available in "company" unchecked. "company" will always have keys available in "user".

I am trying to create an object like this and use "name" property to create checkbox and "isChecked" to make it checked.

Code:
{
  "output": [{
    "serviceId": "useradmin",
    "properties": []
  }, {
    "serviceId": "enett",
    "properties": [{
      "mailbox": [{
        "name": "mybox",
        "isChecked": true
      }, {
        "name": "testBox",
        "isChecked": false
      }]
    }, {
      "b2bcid": [{
        "name": "TEST12345",
        "isChecked": true
      }]
    }]
  }, {
    "serviceId": "portal-kar-restricted",
    "properties": [{
      "ssn-concession": [{
        "name": "Ja",
        "isChecked": true
      }]
    }, {
      "account": [{
        "name": "ashasjkdhasjkhd",
        "isChecked": true
      }]
    }]
  }]
}

<p>I have two objects and require to merge those and create a new One.</p>
<p>Both has "serviceId" and "properties".</p>
<pre><code>var user = {
"presentForUser": [{
"serviceId": "useradmin",
"properties": []
}, {
"serviceId": "enett",
"properties": [{
"mailbox": ["mybox"]
}, {
"b2bcid": ["TEST12345"]
}]
}, {
"serviceId": "portal-kar-restricted",
"properties": [{
"ssn-concession": ["Ja"]
}, {
"account": ["ashasjkdhasjkhd"]
}]
}]
}
</code></pre>
<pre><code>var company = {
"presentForCompany": [{
"serviceId": "useradmin",
"properties": []
}, {
"serviceId": "invoice-archive",
"properties": []
}, {
"serviceId": "enett",
"properties": [{
"mailbox": ["mybox", "testBox"]
}, {
"b2bcid": ["TEST12345"]
}]
}, {
"serviceId": "transhist",
"properties": []
}, {
"serviceId": "BS-Arkiv",
"properties": []
}, {
"serviceId": "sepaonline-dt2",
"properties": []
}, {
"serviceId": "sepaonline-ncb",
"properties": []
}, {
"serviceId": "sepaonline-pbs",
"properties": []
}, {
"serviceId": "BS-web",
"properties": []
}, {
"serviceId": "ClearingDBABankReg",
"properties": []
}, {
"serviceId": "BS-Creditor",
"properties": []
}, {
"serviceId": "portal-kar-restricted",
"properties": [{
"ssn-concession": ["Ja"]
}, {
"account": ["ashasjkdhasjkhd"]
}]
}, {
"serviceId": "Sepa-Customer-Service",
"properties": []
}, {
"serviceId": "examples",
"properties": [{
"access": ["A", "B", "C", "D", "E"]
}]
}, {
"serviceId": "hobo",
"properties": [{
"role": ["admin", "exela_admin_superuser", "exela_standard_role_1", "exela_standard_role_2", "exela_superuser"]
}]
}, {
"serviceId": "peppol-kportal",
"properties": [{
"role": ["ROLE_PEPPOL_KPORTAL"]
}]
}]
}
</code></pre>
<p>I need to compare both the object based on "serviceId" and create a check box for values available inside "mailbox" or "account"(just an example) and keep the common values (from both the object) checked and values available in "company" unchecked. "company" will always have keys available in "user".</p>
<p>I am trying to create an object like this and use "name" property to create checkbox and "isChecked" to make it checked.</p>
<pre><code>{
"output": [{
"serviceId": "useradmin",
"properties": []
}, {
"serviceId": "enett",
"properties": [{
"mailbox": [{
"name": "mybox",
"isChecked": true
}, {
"name": "testBox",
"isChecked": false
}]
}, {
"b2bcid": [{
"name": "TEST12345",
"isChecked": true
}]
}]
}, {
"serviceId": "portal-kar-restricted",
"properties": [{
"ssn-concession": [{
"name": "Ja",
"isChecked": true
}]
}, {
"account": [{
"name": "ashasjkdhasjkhd",
"isChecked": true
}]
}]
}]
}
</code></pre>
 

Latest posts

Top