How To Define My Variable Structure?
I want to create something as following: var collectoin= [ 'title1' => {'subtitle:'sub1', 'contents':'sub content 1' }, 'title2' => {'subtitle:'sub2', 'contents':'sub co
Solution 1:
Notice that the object presented by @juvian does not have a defined ordering of the keys (in contrast to PHP associative arrays, for example). I guess you want an ordered collection, for which you have to use an array:
var collection = [
{'title': '1', 'subtitle':'sub1', 'contents':'sub content 1'},
{'title': '2', 'subtitle':'sub2', 'contents':'sub content 2'},
{'title': '3', 'subtitle':'sub3', 'contents':'sub content 3'}
];
Solution 2:
That does not work in javascript, you should try to read about javascript objects and arrays before asking here. Anyway, the correct syntax would be:
var collection=
{
'title1' : {'subtitle':'sub1', 'contents':'sub content 1' },
'title2' : {'subtitle':'sub2', 'contents':'sub content 2' },
'title3' : {'subtitle':'sub3', 'contents':'sub content 3' }
}
Post a Comment for "How To Define My Variable Structure?"