You’ll probably want to use array mapping to access each result individually. Here’s an example:
// Let's assume the results are stored the variable, result,
// which is an array of events returned by VexDB
results = { sku: "", ...}, ...];
// Now, let's say we want to get the names of each event
// This code will loop through each event and create a new array of their names
let names = results.map( function(event) { return event.name } );
console.log(names); // "2018 VEX WORLDS", "CREATE US OPEN"] or whatever
Now, for a more concrete example, using the fetch API:
let now = new Date().toISOString();
fetch("https://api.vexdb.io/get_events?date=" + now); // Get's events that are currently ongoing
.then( res => res.json() ) // Parse the result
.then( events => events.map( event => event.name ) );
.then(console.log); // "2018 VEX WORLDS", "CREATE US OPEN"] or whatever
The meat of the example is
.then( events => events.map( event => event.name ) );
, which is fairly straightforward:
- The
=>
is what’s know as a fat arrow function.
a => a * 2
is the same as
function(a) { return a * 2 }
- The
events.map
performs the passed function on each item in a array, and returns the results. The passed function takes the event object and returns the event’s name. This means that the final console log will output the array of names, like the first example.
Hope that made sense, please ask if you have any questions