我正在使用 jquery grep 搜索一组对象,并希望在搜索中包含通配符。例如,我有一个数组如下:
courses = [
{code: 'ENCH3TH', otherFields: otherStuff},
{code: 'ENCH3THHS1', otherFields: otherStuff},
{code: 'ENCH3TH2', otherFields: otherStuff},
{code: 'ENCH4RT', otherFields: otherStuff},
{code: 'ENCH4MT', otherFields: otherStuff}]
我想获得所有带有 ENCH3TH 前缀的课程。我尝试过
var resultSet = $.grep(courses, function(e){ return e.code == 'ENCH3TH/'; });
..无济于事(注意在“ENCH3TH”之后使用“/”作为通配符)。