简体   繁体   English

访问位于主数组内的数组内的对象数据

[英]Accessing the object data inside an array which is inside the main array

Here is my JSON DATA -这是我的 JSON 数据 -

    allsurvey[
{eachquestion:
        [{question:sdvsd,
        answeroptions:[fsdf,sdf],
        questiontype:multiChoice},

        {question:sdf,
        answeroptions:sdf,
        questiontype:textbox}],
    noofques:2,
    surveytitle:aaaa
    }
]

I want to access the values inside the array "eachquestion" ie, question, answeroptions我想访问数组“eachquestion”中的值,即问题,答案选项

A possible data structure could be this.可能的数据结构是这样的。 I add an example with access to the items:我添加了一个可以访问项目的示例:

 var object = { allsurvey: [{ eachquestion: [{ question: 'sdvsd', answeroptions: ['fsdf', 'sdf'], questiontype: 'multiChoice' }, { question: 'sdf', answeroptions: 'sdf', questiontype: 'textbox' }], noofques: 2, surveytitle: 'aaaa' }] }; object.allsurvey.forEach(function (a) { a.eachquestion.forEach(function (b) { document.write(Object.keys(b).map(function (k) { return k + ': ' + b[k]; }).join('<br>')); document.write('<hr>'); }); });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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