https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
According to documentation, indexOf returns -1 only when value is not found in array.
Check your School array and email value before calling indexOf. You can use debugger or just simply add console.log before calling indexOf.
deleteDetails = (email) => {
console.log(email);
console.log(School);
var index = School.indexOf(email);
}
If your email element is string "[email protected]", your array should contain string elements.
var email = "[email protected]";
var emails = ["[email protected]", "[email protected]"];
console.log(emails.indexOf(email));
// expected output: 0
Edit: Considering comments below, your callback method should return the index of the element. So deleteDetails function should be like this.
deleteDetails(email, index) {
// code
}
Let's consider Flatlist for listing.
<FlatList
data={this.props.data}
extraData={this.state}
keyExtractor={this._keyExtractor}
renderItem={this._renderItem}
/>
_renderItem = ({item, index}) => (
<MyListItem
id={item.id}
onPressItem={this._onPressItem}
selected={!!this.state.selected.get(item.id)}
title={item.title}
onDeleteButtonPressed={(item, index) => this.deleteDetails(item,index)}
/>
);
And you must create an onDeleteButtonPressed prop and call it when button pressed in component to trigger deleteDetails function.
Schoolarray?console.log(School)value, I just wanted to know whether it is string or object.