function where(collection, source) {
var arr = [];
// What's in a name?
arr = collection.filter(function(x){
var tmpAll = true;
for(var prop in source)
{
if(x.hasOwnProperty(prop) && source.hasOwnProperty(prop) )
{
if(x[prop] != source[prop])
{
tmpAll = false;
break;
}
}else
{
tmpAll = false;
break;
}
}
if(tmpAll)
{
console.log(x);
return x;
}
});
return arr;
}
where([{ first: "Romeo", last: "Montague" }, { first: "Mercutio", last: null }, { first: "Tybalt", last: "Capulet" }], { last: "Capulet" });
Bonfire: Where art thou
最新推荐文章于 2018-09-02 16:47:03 发布