0

I want to merge two JavaScript objects.

device: [{devHardwareId:"40A8F065E465",deviceId:67,deviceIp:"192.168.2.3",deviceName:"DESKTOP-IV0H659"}]

peripherals:[{
    "peripheralId": 3,
    "perHardwareId": "AVtech-Cam",
    "peripheralName": "BackGate",
    "peripheralType": "Video",
    "isActive": true,
},
{
    "peripheralId": 1,
    "perHardwareId": "Logitech-Cam",
    "peripheralName": "FrontCam",
    "peripheralType": "Video",
    "isActive": true,
}]

In above examples the device can contains several peripherals. I want to merge it using AngularJs.then it should be like below.

 device :{devHardwareId:"40A8F065E465",
deviceId:67,
deviceIp:"192.168.2.3",
deviceName:"DESKTOP-IV0H659",
peripherals:{
    "peripheralId": 3,
    "perHardwareId": "AVtech-Cam",
    "peripheralName": "BackGate",
    "peripheralType": "Video",
    "isActive": true,
},
{
    "peripheralId": 1,
    "perHardwareId": "Logitech-Cam",
    "peripheralName": "FrontCam",
    "peripheralType": "Video",
    "isActive": true,
}
}

How can I do that task using AngularJs.

1
  • Why using AngularJs? That's basic JavaScript. Commented Apr 6, 2018 at 13:47

1 Answer 1

2

AngularJS has nothing to do with it. You can use simple JavaScript for this:

let device = [{"devHardwareId":"40A8F065E465","deviceId":67,"deviceIp":"192.168.2.3","deviceName":"DESKTOP-IV0H659"}];
const peripherals = [{"peripheralId":3,"perHardwareId":"AVtech-Cam","peripheralName":"BackGate","peripheralType":"Video","isActive":true},{"peripheralId":1,"perHardwareId":"Logitech-Cam","peripheralName":"FrontCam","peripheralType":"Video","isActive":true}];

device[0].peripherals = peripherals;
console.log(device[0]);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.