I have the next array:
0: {id: "10", tipo: "work"}
1: {id: "11", tipo: "work"}
2: {id: "24", tipo: "school"}
3: {id: "9", tipo: "work"}
4: {id: "25", tipo: "school"}
What I want to do is to remove an element from the array where two values match, for example, if id = 24 and tipo = school, the array at the position 2, must be removed, I have this function to find the array key by the values:
function eliminarElementoArray(array,val1,val2){
for (var i=0; i<array.length; i++){
if (array[i].id == val1 && array[i].tipo == val2)
return i;
else
return false;
}
}
The function does not work correctly, in some cases it returns false, others, it returns an incorrect value.
Finally here is where the array values are removed, but it does not work because the previous function does not return the correct values:
selected.splice( eliminarElementoArray(selected, id, tipo), 1);
If someone can help me, I would be grateful.