I want to put the values I got by hitting the API in the array and take them out at any time.
const http=axios.create({
baseURL: 'base-url',
})
vara = [ ]
function addArray() {
http.get('/hoge/fuga', {data:{}}.then(response=>{
a. push (response.data.name)
})
}
Array.from({length:30}.map()=>{
addArray()
console.log(a[0])
})
Some source codes are omitted, but console.log(a[0])
means undefined
.
console.log(a)
will look like the following, and I think I can get it with index:0 but I can't.
[ ]
0: 'Name'
length —0
__proto —Array(0)
concat —f concat()
It's long, so I'll skip it.
Why can't I get it?
javascript axios
I don't think I can get it.
When you run console.log(a[0])
,
.then(response=>{
a. push (response.data.name)
})
Isn't it just that the callback has not been called and the value has not been set yet?
352 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
356 I want to change the format (date and time display) of the legend in chronological order.
363 Logging Out with the Application Load Balancer and Authentication Using Cognito
365 FileNotFoundError in json: What is the difference between these two?
© 2023 OneMinuteCode. All rights reserved.