Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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.
Posted
Updated 26-Jun-14 21:06pm
v2
Comments
Thanks7872 27-Jun-14 3:07am    
Don't repost questions. If you don't receive any response to your old question,try improving it.

1 solution

Congratulations! You already created a valid example. Your dd is the array of 1 element, which is the object with two properties, data1 and data2, 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 as dd[0].data1 or dd[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:
JavaScript
dd[0].data1["someIndex"] = "some value";


—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900