Data Structures

This section discussed the Core.Arrays manipulation utilities and Core.LargeMap associative array wrapper class.

JavaScript provides two fairly powerful data structures in the forms of associative arrays and sequential arrays.

Sequential Arrays

Sequential arrays in JavaScript are instantiated using either the Array object or the object literal [ ]. There are several useful methods for adding and removing items to an array, e.g., push() and splice(). JavaScript arrays provide many of the capabilities of an ArrayList object found in other languages, such as the ability to insert and remove items. It is strongly recommended that you read a JavaScript tutorial and familiarize yourself with the available methods in the Array object, as they can be quite useful.

The Core.Arrays namespace provides a few additional methods which are useful for manipulating arrays. Though efficiently coded, these methods are not particularly fast when dealing with large arrays. The following methods are provided:

  • Core.Arrays.containsAll(): Determines if one array contains all of the items found in another.
  • Core.Arrays.indexOf(): Determines the first index of a specific object within an array. Returns -1 if the object is not found.
  • Core.Arrays.remove(): Removes the first instance of a specific object within an array.
  • Core.Arrays.removeDuplicates(): Removes any duplicate items from the array. The order of the array is not preserved.

Associative Arrays

Associative arrays in JavaScript are in fact nothing more than JavaScript objects. Creating an associative array is as simple as invoking new Object() or preferably just using the { } object literal syntax. If you are unfamiliar with these concepts, you should strongly consider reading a JavaScript tutorial.

Core.Arrays.LargeMap

Regrettably, Internet Explorer browsers can be very inefficient when handling associative arrays (objects) of which properties are frequently added and removed. Thus the Core.Arrays.LargeMap provides a thin wrapper around an associative array object to work around this issue.