У меня проблема со следующим методом. Я являюсь следующей ошибкой Cannot read property 'selectedMAP' of undefined
.
const selectedPlan = {"name": "basic", "amount": 1000}
let dependantsCost = 0;
for (let i = 0; i < this.planCosts[0].selectedMAP.length; i++) {
for (let j = 0; j < this.planCosts[0].selectedMAP[i].options.length; j++) {
if (selection.medicalAid.numberOfAdultDependants > 0) {
const costForAdultDependant = this.planCosts.filter(x => x.selectedMAP[i].options[j].optionName.toLowerCase() == selectedPlan.name.toLowerCase())[0].selectedMAP[i].options[j].adultDependantAmount;
const numberOfAdultDependants = selection.medicalAid.numberOfAdultDependants;
dependantsCost += numberOfAdultDependants * costForAdultDependant;
}
}
}
Это набор данных, который я фильтрую на
[
{
"corporateId": "a682fafc-372a-4bbf-9b42-fe8b35cc437f",
"selectedMAP": [
{
"mapId": 32,
"mapName": "one",
"active": true,
"options": [
{
"optionId": 49,
"optionName": "basic",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
},
{
"optionId": 50,
"optionName": "advanced",
"memberAmount": 2000,
"adultDependantAmount": 1000,
"childDependantAmount": 2000,
"active": true
}
]
},
{
"mapId": 33,
"mapName": "two",
"active": true,
"options": [
{
"optionId": 51,
"optionName": "lite",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
},
{
"optionId": 52,
"optionName": "heavy",
"memberAmount": 2000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
}
]
}
]
}
]
this.planCosts [0] равно этому
{
"corporateId": "a682fafc-372a-4bbf-9b42-fe8b35cc437f",
"selectedMAP": [
{
"mapId": 32,
"mapName": "one",
"active": true,
"options": [
{
"optionId": 49,
"optionName": "basic",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
},
{
"optionId": 50,
"optionName": "advanced",
"memberAmount": 2000,
"adultDependantAmount": 1000,
"childDependantAmount": 2000,
"active": true
}
]
},
{
"mapId": 33,
"mapName": "two",
"active": true,
"options": [
{
"optionId": 51,
"optionName": "lite",
"memberAmount": 1000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
},
{
"optionId": 52,
"optionName": "heavy",
"memberAmount": 2000,
"adultDependantAmount": 500,
"childDependantAmount": 500,
"active": true
}
]
}
]
}
Есть идеи, почему это может привести к ошибке?