I try to get index, but it's always -1.
JS:
close : function(component, event, helper) {
let vacancies = component.get("v.vacancies"); //an array
let vacancy = event.getSource().get("v.name"); //name - the obct's Id from iteration
const index = vacancies.indexOf(vacancy);
vacancies.splice(index, 1);
component.set("v.vacancies", vacancies);
},
cmp:
<aura:iteration items="{!v.vacancies}" var="vacancy">
<span class="spanButtonClose">
<lightning:buttonIcon name="{!vacancy.Id}" iconName="utility:close" onclick="{!c.close}"/>
</span>
</aura:iteration>
What is wrong here? It's just delete the last one object.