-2

Can anyone explain why this works:

filteredArray = contacts.filter(
  (contact: Contact) => contact.name.toLowerCase().includes(term.toLowerCase())
);

but this doesnt:

filteredArray = contacts.filter((contact: Contact) => {
  contact.name.toLocaleLowerCase().includes(term.toLocaleLowerCase());
});

I'm at a loss as to why simply adding curly braces here seems to break this.

hego64
  • 345
  • 1
  • 5
  • 17

1 Answers1

3

if you are using curly braces, then you have to use return keyword. A single line statement doesnot need curly braces:

filteredArray = contacts.filter((contact: Contact) => {
  return contact.name.toLocaleLowerCase().includes(term.toLocaleLowerCase());
});
Sunil Lama
  • 4,531
  • 1
  • 18
  • 46