【发布时间】:2019-05-28 17:54:56
【问题描述】:
使用过滤器()
使用运动员数据数组和.filter():
仅返回运动员收入超过 7 个字符的运动员对象
- 将返回的数据存储在一个新的
results变量中 * - 注意:
不要删除运动员数据变量
-
不要更改任何运动员数据内容
const athleteData = [ { athlete: 'Lionel Messi', team: 'Barcelona', income: 40000000 }, { athlete: 'Cristiano Ronaldo', team: 'Juventus', income: 30000000 }, { athlete: 'Neymar', team: 'Paris Saint-Germain', income: 36800000 }, { athlete: 'Eden Hazard', team: 'Chelsea', income: 10400000 }, { athlete: 'Mohamed Salah', team: 'Liverpool', income: 4680000 }, { athlete: 'Kylian Mbappé', team: 'Paris Saint-Germain: An American Musical', income: 17500000 }, { athlete: 'Luka Modrić', team: 'Real Madrid', income: 9360000 }, { athlete: 'Harry Kane', team: 'Tottenham Hotspurs', income: 17600000 }, { athlete: 'Kevin De Bruyne', team: 'Manchester City', income: 5980000 }, { athlete: 'Paul Pogba', team: 'Manchester United', income: 15080000 } ]; const results = 'Replace this message with your code!'; console.log(results);** 我想做的方式是**:
const results = playerData.filter(sorted => sorted.income.length > 7);
【问题讨论】:
-
发布的问题似乎根本没有包含any attempt 来解决问题。 StackOverflow 期待您 try to solve your own problem first,因为您的尝试有助于我们更好地了解您想要什么。请编辑问题以显示您尝试过的内容,以说明您遇到minimal reproducible example 的特定障碍。欲了解更多信息,请参阅How to Ask 并拨打tour。
-
它看起来像一个作业,所以这可能是你得到的,但是基于数字字符数的过滤很奇怪。例如
1000.00有 7 个字符,但这可能不是您想要的。
标签: javascript arrays object ecmascript-6