Reputation:
How can I do something similar to the below
result = $.grep(data, function(e){ return e.firstname == name; });
with having name to be a regex expression, i.e. name starts with "Kevin*"
Upvotes: 0
Views: 7515
Reputation: 253486
Without testing, I'd suggest:
result = $.grep(data, function(e){
return new RegExp('^Kevin').test(e.firstName);
});
To use a variable then the above can be rewritten to:
var name = 'Kevin';
result = $.grep(data, function(e){
return new RegExp('^' + name).test(e.firstName);
});
References:
Upvotes: 2