- var arr1:Array = ["1","2","3","4"];
- delete arr1[0];
- trace(arr1.length); //Output 4 (although delete can delete elements in the array, it does not change the length of the array)
- var arr2:Array = ["1","2","3","4"];
- arr2.splice(0, 1);
- trace(arr2.length); //Output 3 (splice also changes the length of the array while deleting the elements of the array)
- var arr3:Array = [];
- trace(arr3.length); //output 0
- arr3[3] = 1;
- trace(arr3.length); //Output 4 (when the array elements are assigned in the way of square brackets + array subscript, the length of the array becomes the maximum subscript +1)
- var arr4:Array = [];
- arr4["字符串key"] = "xxxxx";
- trace(arr4.length); //Output 0 (string subscripting does not change the length of the array)
- arr4["5"] = "xxxxx";
- trace(arr4.length); //Output 6 (if the word string is a pure number, it will be treated as a number)
- arr4["010"] = "xxxxx";
- trace(arr4.length); //Output 6 (different from int("010")==10, the subscript of the array will not be converted to int(), the result of arr4["010"] = "xxxxx" is There is an additional key of "010" in arr4, and the length of arr4 remains unchanged)
as3 study notes 1: the length of the array
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325240939&siteId=291194637
Recommended
Ranking