I have a lightning component with an array of checkboxes which are loaded dynamically where I select a field on account as a criteria. For test purposes I used Billingcity.
The filter works for this part and returns the selected cities. The second part is where I want to return all the records based on the selected cities.
The error I get from this second part is variable is undefined. In my code is defined the variable so why is it still giving me this error?
Component
<aura:attribute name="selectedCities" type="Account[]" default="[]" description="accounts" />
Javascript
checkboxes
.filter(checkbox => checkbox.get("v.value")) // Get only checked boxes
.forEach(checkbox => selected.push(checkbox.get("v.label"))); // And get the labels
component.set("v.selectedCities", selected); // Set to display
console.log('v.selectedCities:'+ selected);
console.log('v.component.get("c.getAllAccounts"):'+ component.get("c.getAllAccounts"));
console.log('filteredAccounts '+ filteredAccounts);
var filteredAccounts = component.get("c.getAllAccounts").filter(account => selectedCities.indexOf(account.BillingCity) > -1);
console.log('filteredAccounts '+ filteredAccounts);
Debug log
v.selectedCities:Burlington
v.component.get("c.getAllAccounts"):SecureAction: [object Object]{ key: {"namespace":"c"} }
filteredAccounts undefined