【发布时间】:2018-10-09 08:35:47
【问题描述】:
如果我有以下数据,我将如何使用 ES6 语法过滤每个 node 中的 students 数组,因此它只返回在 subjects 中具有特定值的学生(例如,subject = '英文')?
数据:
[
{
"node": {
"name": "Miss Jones",
"students": [
{
"name": "John",
"subjects": ["English", "Maths"]
},
{
"name": "Sarah",
"subjects": ["Geography"]
}
]
}
},
{
"node": {
"name": "Mr Hudson",
"students": [
{
"name": "Joe",
"subjects": ["Maths", "French"]
},
{
"name": "Samantha",
"subjects": ["English"]
}
]
}
}
]
预期输出:
[
{
"node": {
"name": "Miss Jones",
"students": [
{
"name": "John",
"subjects": ["English", "Maths"]
}
]
}
},
{
"node": {
"name": "Mr Hudson",
"students": [
{
"name": "Samantha",
"subjects": ["English"]
}
]
}
}
]
谢谢!
【问题讨论】:
标签: javascript ecmascript-6 filtering