Home > Backend Development > PHP Tutorial > js中Array对象疑义

js中Array对象疑义

WBOY
Release: 2016-06-13 11:57:53
Original
1067 people have browsed it

js中Array对象疑问
DOM中有一组这样的input节点,假设现在只有一个:

<br /><input class="js_count" pid="3" value="1" /><br />
Copy after login


我想获取所有pid和value,组织一个数组或对象传给其他函数
<br />var count = new Array();<br />$('.js_count').each(function(){<br />    var input = $(this);<br />    var pid = input.attr('pid');<br />    var val = input.attr('value');<br />    count[pid] = val;<br />});<br />data = {<br />    count : count<br />};<br />
Copy after login


但是我alert(count)得到的是:,,,1,是在一次count[pid] = val;的瞬间造成的,pid=3,但是从count[0]到count[2]都产生了一个undefined,我把new Array()换成了new Object()就没事了
请问这个是Array对象的特性吗?
------解决方案--------------------
是的,是Array对象的特性
会补齐未定义的下标

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template