next up previous contents
Next: splice Up: Methods Previous: slice   Contents


sort

Description

Sorts the array in place, without making a copy. If the compareFunction parameter has not been specified, Ffish Script sorts the elements in place using the "<" comparison operator.


Syntax

array1.sort([compareFunction])


Parameters

compareFunction
An optional comparison function used to determine the sorting order of elements in an array. It must return one of the following values: A negative value if the first argument passed is less than the second argument. Zero if the two arguments are equivalent. A positive value if the first argument is greater than the second argument.


Returns

Nothing.


Example

function sortfunc(a, b)
{
    num1 = parseInt(a.substr(1));
    num2 = parseInt(b.substr(1));
    return num1 - num2;
}

a = ["a0", "a1", "a11",
    "a2", "a21", "a3", "a31"];
a.sort(sortfunc);
trace(a);
//output: a0,a1,a2,a3,a11,a21,a31




Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.