简体   繁体   中英

How to constructing Javascript Array with predefined format

From AJAX Call i am constructing this data in my server

{data:[{one:"1",two:"2"},{one:"3",two:"3"}]}

I am able to access this data using data.jobs[2].one;

My question is that , is it possible to construct a similar array inside javascript also I mean this way :

var data = [{one:1,two:2},{one:3,two:3}];

Please help , thank you very much

To access a value using data.jobs[2].one you would need a structure like this:

var data = {
  jobs:[
    {one:"1",two:"2"},
    {one:"3",two:"3"}
  ]
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM