var users = [
{id: 1, name: '一'},
{id: 2, name: '二'},
{id: 3, name: '三'},
{id: 4, name: '四'},
]
Array.prototype.myFind = function (conditionFunc) {
for (var i = 0; i < this.length; i++) {
if (conditionFunc(this[i], i) {
return this[i]
}
}
}
Array.prototype.myFindIndex = function (conditionFunc) {
for (var i = 0; i < this.length; i++) {
if (conditionFunc(this[i], i) {
return i
}
}
}
var ret = users.myFind(function (item, index) {
this.id === 2
}
网友评论