Reputation: 153
I'm trying to make a simple trivia discord bot, i'm fairly new to JavaScript and can't seem to solve the problem.
http://prnt.sc/u7rrbk this is the code trying to get a question from https://opentdb.com/api_config.php
Not quite sure how to get the data from the array, everything that i've tried so far returns undefined.
this is what shows up in console https://prnt.sc/u7rs33
Upvotes: 0
Views: 62
Reputation: 8402
// since `results` is an array, you should change:
trivia.results.category;
// to:
trivia.results[0].category; // [0] gets first value in array
// example:
const obj = {
results: [{
something: true
}]
};
console.log(obj.results.something); // undefined
console.log(obj.results[0].something); // true
Upvotes: 1