[Repost]我需要创建数组并添加对象然后使用Jquery为此对象添加数组 [英] [Repost] I Need To Create Array And Add Object Then Add Array For This Object Using Jquery
本文介绍了[Repost]我需要创建数组并添加对象然后使用Jquery为此对象添加数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要创建数组并添加对象然后为此对象添加数组请为此任何代码提供
结果: var dd = [{data1:[23,34,45,34,22],data2:[32,34,54,56,55]}];
请举例。
解决方案
恭喜!您已经创建了一个有效的示例。您的dd
是1个元素的数组,它是具有两个属性的对象,data1
和data2
,每个都是包含5个整数元素的数组。
现在,请注意在Javascript中的数组和记录/结构对象是相同的,只有初始化语法不同,但您可以使用两种方法对对象进行索引。例如,data1
可以称为dd [0] .data1
或dd [0 ] [ DATA1]
。任何对象都可以作为索引。 Javascript对象实际上是关联容器。请参阅:
http://en.wikipedia.org/wiki/Javascript#Dynamic [ ^ ],
http://en.wikipedia.org/wiki/Associative_array [ ^ ]。
当你的对象被初始化时关联容器(数组),无论何种类型,您都可以随时添加任何新的键/值对:
dd [ 0 ]。data1 [ someIndex] = 某些值;
< DD> -SA
i need to create array and add object then add array for this object please any give code for that one
result: var dd=[{data1:[23,34,45,34,22],data2:[32,34,54,56,55]}];
please give examples.
解决方案
Congratulations! You already created a valid example. Yourdd
is the array of 1 element, which is the object with two properties,data1
anddata2
, each of them are the arrays with 5 integer elements.
Now, note that in Javascript the array and record/structure objects are the same, only the initialization syntax is different, but you can use both ways of indexing on objects. For example,data1
can be referred asdd[0].data1
ordd[0]["data1"]
. Any object can serve as the index. Javascript object are actually associated containers. Please see:
http://en.wikipedia.org/wiki/Javascript#Dynamic[^],
http://en.wikipedia.org/wiki/Associative_array[^].
When your object is initialized as such associated container (array), you can always add any new key/value pair, no matter of what types:
dd[0].data1["someIndex"] = "some value";
—SA
这篇关于[Repost]我需要创建数组并添加对象然后使用Jquery为此对象添加数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文