find 和 findIndex 方法原理
var arr = [
{id: 1, name: 'li 01'},
{id: 2, name: 'li 02'},
{id: 3, name: 'li 03'},
{id: 4, name: 'li 04'},
]
Array.prototype.myFind = function(callback) {
for(var i = 0; this.length; i++) {
if(callback(this[i], i)) {
return this[i]
}
}
}
var rel = arr.myFind(function(item, index) {
return item.id === 3
})
console.log(rel)