0

I am working on search. I am filtering my array based on search input. Here's my code:

const filtered = list.filter((m) =>
  m.toLowerCase().includes(search.toLocaleLowerCase())
);

Now I want my filtered array to be sorted based on startsWith().

For example, I have an array

[brother, brothersmad, other]

and my search search input is other. I want other to be on top.

Penny Liu
  • 15,447
  • 5
  • 79
  • 98
Musadiq Khan
  • 174
  • 7

0 Answers0