Reputation: 1
Hi i dont't know how to compare each elements of the array to the state:
doesCustomerExist = () => {
const { customers } = this.props;
let result = customers.map(c => c.phone)
if(result === this.state.phone)
return (console.log('already exist'))
console.log(result)
}
Upvotes: 0
Views: 2818
Reputation: 18515
For this simply use Array.inlcudes:
const phone = "123";
const customers = ["111", "222", "333", "123"];
const isFound = customers.includes(phone)
console.log(isFound);
Upvotes: 1