
=== Build an Array of Objects from Another Array ===

Working with JSON data collections in //Triggers//, //Formatters// and //Dashboard Scene// initialization scripts
often includes searching and processing collections of objects found in ''Query Result'' objects or ''Controls'', such 
as ''Choice'' or ''Grid''.  

//Array// and //Map// are common and useful collections that are often returned as part of a result data Object (SDO). In this
example an array of strings is converted into a map with key and value that are the same.  Other map value initialization 
is possible using various techniques.

<sxh DSQL; gutter: true;>
// assign your array here using copied path:
var arrayOfStringCodes = foundData.enAspects.someKey; 
// now you can map your array of strings into array of choice objects
var choices = arrayOfStringCodes.map(function(code){
    return {
      label: code,
      value: code,
      selected: code == event.data.name
    };
  });
</sxh>

=== Lodash Object Find ===

[[wp>Lodash]] is a popular javascript library that allows users to work with data collections such as
map, array and list.  It alows users to easily search and manipulate JSON data.  This can be very
useful when working with large objects returned form the data fabric and may be used to perform additional
sorting or filtering of cached result sets. A Map object is provided as part of the API an included in the
functional script of the RTAI environment.  It provides standard methods for random key data manipulation
and search as welas other convenience methods.

<sxh DSQL; gutter: true;>
   // lodash example of find(.) by key
   var fElement = _.find(sourceData.rtaiKnowledgeGraph.kEngrams,['refKeyPredicate', event.data.name]);
   console.log('Found Data:', fElement);
   // get Aspect icd code array..
   var ICD_Codes = fElement.enAspects.ICD10_cdes; 
   // create Choices object from array of Codes
   var choices = ICD_Codes.map( function(code) {
      return {
      	 label: code,
      	 value: code,
         selected: code == event.data.name
       };
    });
</sxh>

=== Iterating and Working With Maps ===

This example loads a popular ''cmOptions'' name/value pair collection returned by an RTAI result object into a
//Map// object by turning them into //Map Entries//.

<sxh DSQL; gutter: true;>

function(html, component) { 
  // verify that data component initialized, since all 
  // queries are asynchronouse and reults are non-preemptive..
  if(component.data != null) {
    // convert object to Map
    var ttypes = new Map(Object.entries(component.data.rtaiOptionCollections.cmOptions));
    // get map element - Type Description
    return ttypes.get(component.getVariable('resourceType'));
    }
  return component.getVariable('resourceType');
}
</sxh>

Sometimes its useful to access //Map// elements by their index.  The //Keys// are returned in the
order they were inserted into a map.  JSON objects returned from the data fabric may be sorted
prior to being sent.  The order in which the elements appear in a JSON objec is considerd absolute
order in whcih the entries are insterted int a //Map//.


<sxh DSQL; gutter: true;>
  
  var appMap = new Map(Object.entries(component.data.rtaiMultiSeriesGrid.cmOptions));
  console.log('First App Item: ' + Array.from(appMap.keys())[0]);
  ..
</sxh>