// 数组filter 如果返回的是true,则留下的是对应的整个元素(item)
var personArr = [
{name: '王港', des: '颈椎不好', sex: 'm'},
{name: '刘莹', des: '我是谁', sex: 'f'},
{name: '王秀莹', des: '我很好看', sex: 'f'},
{name: '刘金雷', des: '你没见过陌生的脸', sex: 'm'},
{name: '刘飞翔', des: '瓜皮刘', sex: 'm'},
];
Array.prototype.myFilter = function (func) {
var arr = [];
var len = this.length;
for(var i = 0; i < len; i++) {
func(this[i], i, this) && arr.push(this[i]);
}
return arr;
}
var newArr = personArr.myFilter(function (item, index, self) {
return item.sex === 'f';
})
console.log(newArr);
console