JavaScript map()函数

map() is key method of an array when it comes to thinking in functional programming terms.

对于函数式编程而言, map()是数组的关键方法。

This example iterates a and builds a new array with the result of executing f() on each a element:

本实施例中迭代a ,并建立与执行的结果的新的数组f()每一个上a元素:

const b = a.map(f)

Given an array, we can use map() to create a new array from the initial one, and then filtering the result using filter(). This short example creates a new array to get the first letter of each item in the list array, and filters the one that matches A:

给定一个数组,我们可以使用map()从初始数组创建一个新数组,然后使用filter()过滤结果。 这个简短的示例创建一个新数组,以获取list数组中每个项目的首字母,并过滤与A匹配的A

const list = ['Apple', 'Orange', 'Egg']
list.map(item => item[0]).filter(item => item === 'A') //'A'

翻译自: https://flaviocopes.com/javascript-map/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值