您可以传递一个测试每个元素的函数。这个
documentation
给出以下示例:
var users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false },
{ 'user': 'pebbles', 'age': 1, 'active': true }
];
_.find(users, function(o) { return o.age < 40; });
因此,您可能正在寻找这样的东西:
_.find(obj.dbColumns, function(o) {
return (new RegExp ([a,b].join('|'))).test( o.yourAttribute );
});
或者,如果只需要子字符串搜索,而不是正则表达式:
_.find(obj.dbColumns, function(o) {
return
o.yourAttribute.indexOf(a) >= 0 ||
o.yourAttribute.indexOf(b) >= 0;
});