options - это массив, который вы не можете напрямую вызвать options.action, вам нужно вызвать options [0] .action, тогда он даст вам объект действия, имеющий заголовок и тип.
Пожалуйста, посмотритекод ниже.
var res = {
"bookhistory" : {
"contents" : [
{
"options" : [
{
"title" : "Predator",
"type" : "CHECKBOX"
},
{
"title" : "Alien",
"type" : "CHECKBOX"
}]
},
{
"options" : [
{
"action" :
{
"title" : "batman",
"type" : "CHECKBOX"
}
}]
}]
}
}
console.log("direclty calling =>",res.bookhistory.contents[1].options[0].action)
// you can use the forEach method, you can check the data basically contents is an array and for the first item options doesn't have action but the second item in the contents have action for the options array.
// inorder to print you can use a if conditon as shown below
console.log("using loops")
res.bookhistory.contents.forEach(o => {
o.options.forEach(so => {
if(so.action){
console.log(so.action)
}else{
console.log(so)
}
})
})