我正在使用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”后使用“/”作为通配符)。