


Interesting JavaScript array length problem code description_javascript skills
May 16, 2016 pm 06:11 PMvar lennon =Array();
lennon["name"]="windy";
lennon["year"]="1989";
lennon["living"]=true;
alert( lennon.length);
Result: lennon.length is 0

Cause:
Increasing array elements in the following way will not change the length of the array
arr["a"]=3;
Second point:
var foo2 = [];
foo2['3'] = 3;
foo2['age'] = 20;
debugger;
alert (foo2.length);

foo2.length is 4 again
All array objects without assignment will be defined as undefined
JavaScript can automatically resize arrays. This automatic resizing mechanism makes out-of-bounds arrays more likely to occur and harder to detect. So pay extra attention to situations like this.

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to remove duplicate elements from PHP array using foreach loop?

PHP array key value flipping: Comparative performance analysis of different methods

PHP array multi-dimensional sorting practice: from simple to complex scenarios

The Art of PHP Array Deep Copy: Using Different Methods to Achieve a Perfect Copy

Application of PHP array grouping function in data sorting

Best Practices for Deep Copying PHP Arrays: Discover Efficient Methods

The role of PHP array grouping function in finding duplicate elements

PHP array merging and deduplication algorithm: parallel solution
