AddThis Social Bookmark Button
Array.reverse()

The reverse() method reverses the order of elements in an array, swapping the last element with the first element, the second-to-last element with the second element, and so on.

var myChest = new Array("cup","ball","hat","spoon","chair");
myChest.reverse();
trace(myChest);
// Output chair,spoon,hat,ball,cup


Array.shift()

The shift() method deletes the first element of an array and then moves all the remaining elements of the array up one position. The affected array's length is reduced by 1. Note that shift() differs from the pop() method, which deletes the last element of an array.

var myChest = new Array("cup","ball","hat");
trace("Now deleting '"+myChest.shift()+"' the new array is : "+myChest);



Array.unshift()
The unshift() method adds a series of elements to the beginning of an array. Elements are added in the order specified. To add elements at the end of an array, use push().

var myChest = new Array("cup","ball","hat");
myChest.unshift("spoon","chair");
trace(myChest);
// Output spoon,chair,cup,ball,hat


Array.slice(startIndex, endIndex)

startIndex : A number specifying the index of the starting point for the slice. If startIndex is a negative number, the starting point begins at the end of the array, where -1 is the last element.

endIndex : A number specifying the index of the ending point for the slice. If you omit this parameter, the slice includes all elements from the starting point to the end of the array. If endIndex is a negative number, the ending point is specified from the end of the array, where -1 is the last element.

The slice() method creates a new array by extracting a series of elements from an existing array. The original array is not modified. The new array is a subset of the elements of the original array, starting with array[startIndex] and ending with array[endIndex - 1].

var myChest = new Array("cup","ball","hat","spoon","chair");
mySlice1 = myChest.slice(1,3);
trace(mySlice1);
// Output ball,hat



Array.sort()

sorts the elements in an array. Flash sorts according to Unicode values. (ASCII is a subset of Unicode.)

var fruits_array = new Array("oranges", "apples", "strawberries", "pineapples", "cherries");
trace(fruits_array); // displays oranges,apples,strawberries,pineapples,cherries
fruits_array.sort();
trace(fruits_array); // displays apples,cherries,oranges,pineapples,strawberries



Array.splice(start:Number, deleteCount:Number [, value0:Object, value1...valueN])

adds and removes elements from an array. This method modifies the array without making a copy.

start An integer that specifies the index of the element in the array where the insertion or deletion begins.

deleteCount An integer that specifies the number of elements to be deleted. This number includes the element specified in the start parameter. If no value is specified for deleteCount, the method deletes all the values from the start element to the last element in the array. If the value is 0, no elements are deleted.

value An optional parameter that specifies the values to insert into the array at the insertion point specified in the start parameter.

var myPets_array = new Array("cat", "dog", "bird", "fish");
trace( myPets_array.splice(1) ); // output dog,bird,fish
trace( myPets_array ); // output cat

var myFlowers_array = new Array("roses", "tulips", "lilies", "orchids");
trace( myFlowers_array.splice(1,2 ) ); // output tulips,lilies
trace( myFlowers_array ); // output roses,orchids

var myFurniture_array = new Array("couch", "bed", "desk", "lamp");
trace( myFurniture_array.splice(1,1, "chair" ) ); // displays bed
trace( myFurniture_array ); // displays couch,chair,desk,lamp


Good luck :)



AddThis Social Bookmark Button
If you think this page is providing useful information, don't hesitate to leave a comment.
flashvalley
 
Copyright ©2006-2008 flashvalley.com - All rights reserved