Could really use some assistance with sorting an array of objects in javascript. My users
array looks like this:
var users = [
{
first: 'Jon',
last: 'Snow',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="85efeaebc5e2eaf1abe6eae8">[email protected]</a>'
},
{
first: 'Ned',
last: 'Stark',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9c7cccdcadddba0ecccc7d4">[email protected]</a>'
},
{
first: 'tywin',
last: 'Lannister',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="84f0fdf3edeac4e3ebf0aae7ebe9">[email protected]</a>'
},
]
I'm working on a method to filter through the object array:
function findMatch(searchTerm, users) {
var results = users.filter(function(user) {
return (user.first === searchTerm || user.last === searchTerm || user.email === searchTerm);
});
return results;
}
The issue I'm facing is that my search parameter searchTerm
must be an exact match to the values in the array... I need it to be able to search based on a partial match instead. Any suggestions?
Your help is greatly appreciated!