Nemeth Attila Nemeth Attila - 7 months ago 10
Javascript Question

How to get array size which is inside an object?

I have an array which contains objects like this:

dataSet = [{question:"",options:[{subject:"",teacher:""}]}]


How can I get the length of the options array?

Answer

dataSet itself an array. So get the first index of it and then length of options in it like following.

var dataSet = [{question:"", options:[{subject:"",teacher:""}]}]
alert(dataSet[0].options.length);