I'm trying to access an array of arrays in javascript but always getting undefined. Here is my code:
const Servers = [{
"ID": 1,
"IP": "192.168.1.11",
"Enabled": true,
},
{
"ID": 2,
"IP": "192.168.1.12",
"Enabled": true,
}
]
const channels = []
const loadChannels = () => {
Servers.map((server, key) => {
if (server.Enabled == true) {
axios.get(server.IP).then((response) => {
if (response.data.response >= 400) {
console.log(response)
} else {
channels.push(response.data.data)
console.log(key, response.data.data) //
}
}).catch((err) => {
console.log(err)
})
}
})
}
loadChannels()
console.log('channels', channels)
console.log('index 0 :', channels[0])
and here is the console output
What am I doing wrong? Can anybody help me please. Many thanks!