Initializing help system before first use

Accessing Array Data

There are several ways to access the data from an InsightArray object.

If you have access to the associated sets you can build up the possible keys for the array using these and iterate over each, calling InsightArray#getValue on each. However, this is very inefficient in most cases as the set data needs to be downloaded separately. The key information is already available in the InsightArray object and you can use one of the follow methods instead.

You can get an iterator for the array and loop through that:
// Using an array iterator
view.withFirstScenario()
   .withEntities('Population')
   .notify(function(scenario) {
       var population = scenario.getArray('Population');
       var iterator = population.getIterator();
       var item;
       while(item = iterator.next()) {
           // item will contain {key: ['UK'], value: 64000000}
       }
   })
   .start();
It is also possible to get a list of all the populated keys for an InsightArray:
var population = scenario.getArray('Population');
var keys = population.getKeys();
// keys will contain an array of composite keys
Finally, it is possible to get a JavaScript array listing all entries of the InsightArray, both keys and values:
var population = scenario.getArray('Population');
var keyValues = population.toObjectArray();
// keyValues will contain be an array of key-value objects
keyValues.forEach(function(entry) {
   // entry.key will be ['UK']
   // entry.value will be 64000000
});