
Array.sort() Method
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Alphabetical Language Reference
|
449
// Set anotherList to ["d", "e"]
anotherList = myList.slice(3);
// Set yetAnotherList to ["c", "d"]
yetAnotherList = myList.slice(-3, -1);
See Also
Array.splice(); “The slice() Method,” in Chapter 11; “The delete Operator,” in Chapter 5
Array.sort() Method
sort the elements of an array
Flash 5
array.sort()
array.sort(compareFunction)
Arguments
compareFunction
An optional function that dictates how to sort
array.
Description
When invoked without the optional compareFunction argument, sort() temporarily converts
the elements of
array to strings and orders the elements according to the Unicode code
points of those strings (approximately alphabetical order for Western European languages).
Alphabetic comparisons and code points are described in “Character order and alphabetic
comparisons” in Chapter 4.
When invoked with a
compareFunction argument, sort() reorders the elements of array
according to the return value of compareFunction, which is a user-defined function that
dictates how to sort any two values in the array. Your user-defined
compareFunction should
be designed to accept two array elements as arguments. It should return a negative number
if the first element should come before the second element; it should return a positive
number if the ...