'javascript: All device data is read into the object
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();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
