Skip to content

📚 4.map

💻 代码实现

typescript
Array.prototype._map = function (callback) {
    return this.reduce((acc, cur, index) => {
        acc.push(callback(cur, index, this))
        return acc
    }, [])
}
const res = [2, 3, 4]
console.log(res._map((_v) => _v ** 2))

Released under the MIT License.