/*for (let i = 0; i < response.length; i++) {
console.log(response[i].id);
console.log(response[i].userID);
console.log(response[i].title);
}*/
//let myJSON = JSON.stringify(obj);
//console.log (myJSON);
document.getElementById(‘container-1’).innerHTML = userID.map(user =>
`
UserID: ${user.id}
Title: ${user.title}
Body: ${user.body}
</div>`
).join(’’)
console.log(obj);
}).catch(function(error){
console.error(“something went wrong with retrieving people”);
console.error(error)
});
ilenia
July 17, 2021, 4:14pm
3
what’s the issue?
I tried executing your code and I get an array of objects
@ilenia I edit my post. I’m trying to render all of the posts that this API returns using json.stringfy() ,map() function.
ilenia
July 17, 2021, 5:10pm
5
what have you tried? the code is still the same
@ilenia I edited my code. please check.
ilenia
July 17, 2021, 6:00pm
7
this is your function, do you get any error?
what result are you getting, what is the wanted result instead?
@ilenia I just wanna render my array of objects. the code you mentioned shows an error for not having function decleration.
ilenia
July 17, 2021, 8:20pm
9
what does the error say exactly?
So what happens if you give the function at line 43 a name? Because if you’re getting that error, then I think it means you’ve just literally put
function (obj) {
...
Into your code, not in as a callback, just straight into the code
Edit: you’re missing a closing }
on that callback function
Edit edit: I’m completely confused now. Have you edited the code you’ve posted several times? because it doesn’t quite make sense unless the replies were about code that isn’t now visible
Did you look in the console? With your current code, it is telling you that userID
is not defined. You want to map over obj
in the callback.
system
Closed
January 16, 2022, 10:08am
13
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.