I have a mock data object, I created a 2 global JS arrays and assigning them to inside map, and printing, but the object doesn't prints comes as undefined.
Following is what I tried
var mock = { "collection_data_status_list": [{ "input_status_list": [{ "device_id": "r0", "sensor_data": { "snmp_yang_sensor": { "path": "IF-MIB:IF-MIB\/ifTable\/ifEntry0" } }, "collection_status": { "state": "ACTIVE_STATE", "error": {}, "reported_time": "1569948062" } }, { "device_id": "r0", "sensor_data": { "snmp_yang_sensor": { "path": "IF-MIB:IF-MIB\/ifTable\/ifEntry1" } }, "collection_status": { "state": "ACTIVE_STATE", "error": {}, "reported_time": "1569948062" } }, { "device_id": "r0", "sensor_data": { "snmp_yang_sensor": { "path": "IF-MIB:IF-MIB\/ifTable\/ifEntry2" } }, "collection_status": { "state": "ACTIVE_STATE", "error": {}, "reported_time": "1569948062" } }, { "device_id": "r0", "sensor_data": { "snmp_yang_sensor": { "path": "IF-MIB:IF-MIB\/ifTable\/ifEntry3" } }, "collection_status": { "state": "ACTIVE_STATE", "error": {}, "reported_time": "1569948062" } }, { "device_id": "r0", "sensor_data": { "snmp_yang_sensor": { "path": "IF-MIB:IF-MIB\/ifTable\/ifEntry4" } }, "collection_status": { "state": "ACTIVE_STATE", "error": {}, "reported_time": "1569948062" } }], "output_status_list": [{ "destination_id": "d0", "destination_context_id": "t1", "device_id": "r0", "sensor_data": { "snmp_yang_sensor": { "path": "IF-MIB:IF-MIB\/ifTable\/ifEntry0" } }, "collection_status": { "state": "ACTIVE_STATE", "error": {}, "reported_time": "1569948062" } }] }, {}], "query_options": { "page_token": "1", "page_size": 100 }, "result": { "request_result": "ACCEPTED", "error": {} } }; var input_list = []; var output_list = []; var newObj = {}; var new1 = mock.collection_data_status_list; debugger; var finalOutput = new1.map(function(item) { var input_list = []; var output_list = []; var newObj = {}; newObj = { input_list: item.input_status_list, output_list: item.output_status_list }; return newObj; }); console.log(newObj);
var mock = {
"collection_data_status_list": [{
"input_status_list": [{
"device_id": "r0",
"sensor_data": {
"snmp_yang_sensor": {
"path": "IF-MIB:IF-MIB\/ifTable\/ifEntry0"
}
},
"collection_status": {
"state": "ACTIVE_STATE",
"error": {},
"reported_time": "1569948062"
}
}, {
"device_id": "r0",
"sensor_data": {
"snmp_yang_sensor": {
"path": "IF-MIB:IF-MIB\/ifTable\/ifEntry1"
}
},
"collection_status": {
"state": "ACTIVE_STATE",
"error": {},
"reported_time": "1569948062"
}
}, {
"device_id": "r0",
"sensor_data": {
"snmp_yang_sensor": {
"path": "IF-MIB:IF-MIB\/ifTable\/ifEntry2"
}
},
"collection_status": {
"state": "ACTIVE_STATE",
"error": {},
"reported_time": "1569948062"
}
}, {
"device_id": "r0",
"sensor_data": {
"snmp_yang_sensor": {
"path": "IF-MIB:IF-MIB\/ifTable\/ifEntry3"
}
},
"collection_status": {
"state": "ACTIVE_STATE",
"error": {},
"reported_time": "1569948062"
}
}, {
"device_id": "r0",
"sensor_data": {
"snmp_yang_sensor": {
"path": "IF-MIB:IF-MIB\/ifTable\/ifEntry4"
}
},
"collection_status": {
"state": "ACTIVE_STATE",
"error": {},
"reported_time": "1569948062"
}
}],
"output_status_list": [{
"destination_id": "d0",
"destination_context_id": "t1",
"device_id": "r0",
"sensor_data": {
"snmp_yang_sensor": {
"path": "IF-MIB:IF-MIB\/ifTable\/ifEntry0"
}
},
"collection_status": {
"state": "ACTIVE_STATE",
"error": {},
"reported_time": "1569948062"
}
}]
}, {}],
"query_options": {
"page_token": "1",
"page_size": 100
},
"result": {
"request_result": "ACCEPTED",
"error": {}
}
};
var new1 = mock.collection_data_status_list;
var input_list = [];
var output_list = [];
debugger;
var finalOutput = new1.map(function(item){
input_list=item.input_status_list;
output_list= item.output_status_list;
});
console.log(finalOutput);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.