Java脚本数组返回数组[0]的所有元素 [英] Java script Array is returning all the elements for array[0]
本文介绍了Java脚本数组返回数组[0]的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨专家,
我在脚本标签的顶部声明了一个这样的数组
var qArr = new Array();
并且通过使用for循环我通过此代码添加元素
qArr.push(element);
我想从中得到单个元素,因为我正在使用这行代码
var item = qArr [index];
但是,遗憾的是它返回了数组中的所有元素。任何人都可以指导我做错了吗?
提前谢谢
(Keerthi Kumar)
解决方案
而不是var qArr = new Array();
尝试var qArr = []
;
有一个建议这里 [ ^ ]以避免new array()
Hi Experts,
I have declared one array at the top of the script tag like this
var qArr = new Array();
and by using for loop I am adding elements to that by this code
qArr.push(element);
I want to get single element from this, for that am using this line of code
var item = qArr[index];
But, Unfortunately it is returning all the elements from the array. Can any one please guide me that where am doing wrong?
thanks in advance
(Keerthi Kumar)
解决方案
Instead ofvar qArr = new Array();
tryvar qArr = []
;
There is a suggestion here[^] to avoidnew array()
.
这篇关于Java脚本数组返回数组[0]的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文