I have the following code which returns an object if the searchText matches a surname or firstname of an object in a object list.
This works
If I enter “”Donald Duck” I get all the Donald’s, no Ducks are returned and it’s not filtered to just Donald Ducks.
What I should get is when I enter Donald. I get all the Donalds with their lastnames, If add a “e” on the end I get no results as it’s spelt wrong. Once I type Duck I only get first and last name matches.
Also need it to work for Duck Donald
Any ideas?
[code]
let matches = studentList.filter(student=>{
const regex = new RegExp(`^${searchText}`, ‘gi’);
return student.Surname.match(regex) || student.Firstname.match(regex);
});