as3 study notes 1: the length of the array

  1. var arr1:Array = ["1","2","3","4"];  
  2. delete arr1[0];  
  3. trace(arr1.length);  //Output 4 (although delete can delete elements in the array, it does not change the length of the array)  
  4.   
  5. var arr2:Array = ["1","2","3","4"];  
  6. arr2.splice(0, 1);  
  7. trace(arr2.length); //Output 3 (splice also changes the length of the array while deleting the elements of the array)  
  8.   
  9. var arr3:Array = [];  
  10. trace(arr3.length); //output 0  
  11. arr3[3] = 1;  
  12. 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)  
  13.   
  14. var arr4:Array = [];  
  15. arr4["字符串key"] = "xxxxx";  
  16. trace(arr4.length); //Output 0 (string subscripting does not change the length of the array)  
  17. arr4["5"] = "xxxxx";  
  18. trace(arr4.length); //Output 6 (if the word string is a pure number, it will be treated as a number)  
  19. arr4["010"] = "xxxxx";  
  20. 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) 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325240939&siteId=291194637