admin管理员组文章数量:1335103
I am making a program that generates a Javascript file. I have never worked with Javascript, so I may be asking a stupid question :) Anyhow, this Javascript files gets initialized with data.
Here is an example line where I initialize an entry in an array with an object that contains two properties whereof one of them is an array containing 3 objects...
Or, well, that was the idea at least... Is there anyway I can do so so "M" bees a real array that can be indexed normally?
W1[242] = {"W":"authors","M":{ "ArrItem0":{"U":32,"S":4.37},"ArrItem1":{"U":38,"S":4.02},"ArrItem2":{"U":406,"S":1.53} } };
I am making a program that generates a Javascript file. I have never worked with Javascript, so I may be asking a stupid question :) Anyhow, this Javascript files gets initialized with data.
Here is an example line where I initialize an entry in an array with an object that contains two properties whereof one of them is an array containing 3 objects...
Or, well, that was the idea at least... Is there anyway I can do so so "M" bees a real array that can be indexed normally?
W1[242] = {"W":"authors","M":{ "ArrItem0":{"U":32,"S":4.37},"ArrItem1":{"U":38,"S":4.02},"ArrItem2":{"U":406,"S":1.53} } };
Share
Improve this question
asked Nov 18, 2011 at 5:36
TomTom
3,63710 gold badges72 silver badges136 bronze badges
3 Answers
Reset to default 4W1[242] = {"W":"authors","M":[ {"U":32,"S":4.37},{"U":38,"S":4.02},{"U":406,"S":1.53} ] };
The array notation is the following, with brackets []
:
W1[242] =
{
"W": "authors",
"M": [{"U":32,"S":4.37}, {"U":38,"S":4.02},{"U":406,"S":1.53}]
};
Depends on how you want to work with what is in M. Here is one option where each element of M is it's own object.
W1[242] = {"W":"authors","M":[ {"U":32,"S":4.37},{"U":38,"S":4.02},{"U":406,"S":1.53} ] };
本文标签: arraysInitializing quotcomplexquot nested javascriptobjectsStack Overflow
版权声明:本文标题:arrays - Initializing "complex" nested javascriptobjects - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742383057a2464477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论