如何使用jQuery或JavaScript动态添加数组 [英] How to add the array dynamically using jquery or javascript
问题描述
我想使用jQuery动态添加数组.我该怎么做.(或)
我想像这样将元素推入数组.
var array = [{"question":"1","answer":"2"}];
我想使用for循环动态地做到这一点
最初我会添加
array.push({"question":"1"});
然后array.push({"answer":"2"});
但我希望元素位于同一array [0] element
但这是作为array [0],array [1]
我怎样才能做到这一点.我正在使用for循环将元素添加到数组中
问候,
Srinivas
Hi,
I want to add the array dynamically using jquery. How can i do that.(or)
I want to push the elements in to array like this.
var array = [{"question":"1","answer":"2"}];
i want to do that dynamically using for loop i mean
initially i will add
array.push({"question":"1"});
then array.push({"answer":"2"});
but i want the elements to in the same array[0] element
but it is taking as array[0],array[1]
How can i do that. I am using for loop to add the elements in to the array
Regards,
Srinivas
推荐答案
请参阅此
这篇关于如何使用jQuery或JavaScript动态添加数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!