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.