Question about Array objects in js

Source: Internet
Author: User
In js, the Array object has a set of such input nodes in the question DOM. suppose there is only one:
 


I want to get all the pid and value, organize an array or object and pass it to other functions.
var count = new Array();$('.js_count').each(function(){    var input = $(this);    var pid = input.attr('pid');    var val = input.attr('value');    count[pid] = val;});data = {    count : count};


But what I get from alert (count) is:, 1, which is produced at the moment of count [pid] = val;, pid = 3, but from count [0] to count [2], an undefined is generated. I replace new Array () with new Object () and it will be okay.
Is this an Array object feature?


Reply to discussion (solution)

Yes, it is the feature of the Array object.
Undefined subscript is added.

Yes, it is the feature of the Array object.
Undefined subscript is added.



Thank you, bamboo.
I have just checked some materials. all PHP variables, including n-dimensional arrays and object attributes, seem to be mapped to the same variable hash table. Therefore, php arrays can be indexed using strings, the use of digital indexes does not require continuity and will not occupy excessive memory. js Array () seems to be the most basic Array implementation in C language, and cannot be a string index, A pile of undefined data is displayed. But some people say that everything in JavaScript is an object. Why does Array () look like this?

The php array is not really an array, but the array name is used.
Js arrays are real arrays and one-dimensional

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.