Actionscript3.0 Arrays Array

Source: Internet
Author: User
Tags array length arrays

1, array does not require all element uniform type, does not support typed array

		var i:int=23;
		var array:array=[122,i, "Asdfasdf", "ASDFASDFASDF"];


2. Initialize and access array elements

Slightly


3, the length of the array

The length of the array is not fixed, and the length of the array can vary with the Members ' additions and deletions.

★ In fact, the length of the array is read by the Getter method, and the length of the setting is setter method, if the length of the set is less than the existing array, you then the index is greater than [original array length-1] elements are discarded. If you set the length of an array to be greater than the existing lengths, the elements from the last element of the original array to the middle of the end of the new array are automatically set to undefined.

The implementation is as follows:

		Public function Get Length (): uint{} public
		function set Length (value:uint): uint{}
You can use an index that exceeds the length to set the element:
		var array:array=["Asss", "Asdfasdf", "ASDFASDFASDF"];
		Array[5]= "DD";
		Trace (array);//ASSS,ASDFASDF,ASDFASDFASDF,,, DD


4. Find IndexOf, LastIndexOf

Camel type function name

Destination array. indexOf (the element to find)

Destination array. lastIndexOf (the element to find)

The target array. indexOf (the element to find, the starting position of the lookup)

The target array. lastIndexOf (the element to find, the starting position of the lookup)

Returns the index if found, otherwise returns-1;


5. Add and remove elements at the end of the array

The push method, which adds one or more elements to the end of the array, returning the new array length

Unshift method, adding one or more elements to the array header, returning the new array length

Pop method, deleting an element at the end of the array, returning the deleted element

Shift method, deleting an element at the header of an array, returning the deleted element

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.