Im trying to pushing each API response on my list :
but unfortunately i got this error
async loadCards() {
try {
const response = await axios.get("https://api.adzuna.com/...");
var list = [];
response.data.results.forEach(elem => {
elem.push(list)
console.log(list)
});
}
catch (error) {
console.log(error);
}
},
CodePudding user response:
I think you are trying to loop through the response and for each result, you wanna enter to the list, right? if so update the code with following
async loadCards() {
try {
const response = await axios.get("https://api.adzuna.com/...");
var list = [];
response.data.results.forEach(elem => {
list.push(elem)
console.log(list)
});
}
catch (error) {
console.log(error);
}
},
Because you wanna push elements to the list you initialized a simple example is
const array1 = ['a', 'b', 'c'];
var newarray = []
array1.forEach(element => {
newarray.push(element)});
Here we are taking elements from array1 and pushing them to the new array. Hope it makes sense now
Answering to your comment as you wanna enter the full response and not each element sepeartely you could use this following
async loadCards() {
try {
const response = await axios.get("https://api.adzuna.com/...");
var list = [];
response.data.forEach(elem => {
list.push(elem)
console.log(list)
});
}
catch (error) {
console.log(error);
}
},
CodePudding user response:
...after that i succeeded put element on the list, the loop iterate on him so got this :
but if i put this code, i have this :
async loadCards() {
try {
const response = await axios.get("https://api.adzuna.com/...");
var list = [];
response.data.forEach(elem => {
list.push(elem)
console.log(list)
});
}
catch (error) {
console.log(error);
}
},