const players = [
{ name: '科比', num: 24 },
{ name: '詹姆斯', num: 23 },
{ name: '保罗', num: 3 },
{ name: '威少', num: 0 },
{ name: '杜兰特', num: 35 }
]
// forEach
Array.prototype.sx_forEach = function (callback) {
for (let i = 0; i < this.length; i++) {
callback(this[i], i, this)
}
}
players.sx_forEach((item, index, arr) => {
// console.log(item, index)
})
// console.log(players)
Array.prototype.sx_map = function (callback) {
let result = []
for (let i = 0; i < this.length; i++) {
callback(this[i], i, this)
result.push( callback(this[i], i, this))
}
return result
}
console