# Array.sortOn()

#### Availability

Flash Player 6.

#### Usage

    my_array.sortOn(fieldName)

#### Parameters

`fieldName` A string that identifies a field in an element of the Array to be used as the sort value.

#### Returns

None.

#### Description

Method; sorts the elements in an array based on a field in the array. If no`fieldName` parameter is passed, the function fails. If multiple `fieldName` parameters are passed, the first field is converted to a string value and the remaining parameters are ignored.

If either of the elements being compared does not contain the field specified in the `fieldName` parameter, the sort defaults to the behavior described in `Array.sort()`.

#### Example

This following example creates a new array and sorts it based on the field `city`:

    var rec_array = new Array();
    rec_array.push( { name: "bob", city: "omaha", zip: 68144 } );
    rec_array.push( { name: "greg", city: "kansas city", zip: 72345 } );
    rec_array.push( { name: "chris", city: "burlingame", zip: 94010 } );
    for(i=0; i<rec_array.length; i++) {
     trace(rec_array[i].name + ", " + rec_array[i].city);
    }
    // results in
    // bob, omaha
    // greg, kansas city
    // chris, burlingame

    rec_array.sortOn("city");
    for(i=0; i<rec_array.length; i++) {
     trace(rec_array[i].name + ", " + rec_array[i].city);
    }
    // results in
    // chris, burlingame
    // greg, kansas city
    // bob, omaha

#### See also

`Array.sort()`