我的任务是从适合特定类别的数据集中打印所有个人的名字;但是,数据集是一个对象数组,它以字符串形式提供全名,例如:
var dataSet = [
{
"name": "John Doe",
"age": 60,
"math": 97,
"english": 63,
"yearsOfEducation": 4
},
{
"name": "Jane Doe",
"age": 55,
"math": 72,
"english": 96,
"yearsOfEducation": 10
}
]
我不能使用除filter(),map()和reduce()之外的任何数组类型的内置函数。
我的代码的最后一块(从对象数组“ dataSet”中获取名称)如下所示:
var youngGoodMath = dataSet.filter(function(person){
return person.age < avgAge && person.math > avgMath;
});
var yGMname = youngGoodMath.map(function (person){
return person.name;
});
console.log(yGMname);
产生一个看起来像这样的字符串数组:
["Jane Doe", "John Doe", "Harry Potter", "Hermione Granger"]
我需要找到一种生产方式:
["Jane", "John", "Harry", "Hermione"]
我怀疑答案在于使用.forEach和.Split(),但是还无法破解...
相关分类