When I write javascript, I want to read all the data of the device into the object, but only the last one is read.
I would like to ask how I can read all the data in the device into obj, thank you.
let data = [
{
"bind": "82218018295591013",
"account": "admin",
"password": "0000",
"devices": [
{
"ip": "192.168.0.88",
"brand_name": "UNIVIEW",
"name": "UNIVIEW"
}
]
},
{
"bind": "94907378021478863",
"account": "admin",
"password": "0000",
"devices": [
{
"ip": "192.168.0.88",
"brand_name": "UNIVIEW",
"name": "UNIVIEW"
},
{
"ip": "192.168.0.89",
"brand_name": "hisharp",
"name": "hisharp"
}
]
}
]
let obj = {};
function getObj() {
for (let i = 0; i < data.length; i++) {
for (let j = 0; j < data[i].devices.length; j++) {
obj.devices = data[i].devices[j];
}
}
return obj;
}
console.log('obj :>> ', obj);
getObj();