Associative Array

An associative array is a set of key value pairs. The value is stored in association with its key and if you provide the key the array will return the value.

          // To create an associative array
contacts = {
    firstname : 'John',
    lastname  :'Smith'
}; 

        
Note:

Notice the similarity to Objects.

An associative array is accessed by a key name.

          // Use the key to access an entry
var value = contacts['firstname']; // value is 'John'

// You can also use dot notation
var value = contacts.lastname; // value is 'Smith' 

        
Note:

The key is always a string, but the value can be any type. See Dynamic Data Types and Objects.

You can loop through the keys of an associative array with the for in loop.

          // Get all the values on the fields on the form
var allValues = NSOA.form.getAllValues();

//Loop through all the values
for( var key in allValues ) {
    NSOA.meta.alert(key + ' has value ' + allValues[key]);
} 

        

See also:

You can change the value using assignment to a property.

          // Using the array notation
contacts['firstname'] = 'Joe';

// Using dot notation
contacts.firstname = 'Joe'; 

        

You can add a new key/value pair by assigning to a property that doesn't exist.

          // Using the array notation
contacts['company'] = 'NetSuite';

// Using dot notation
contacts.company ='NetSuite'; 

        
Important:

Some fields return an object. See Object Fields.