I am trying to use filter
(I don't think map
applies here, but I am not sure) to extract an element from an array of dictionaries which themselves contain dictionaries.
let participants = [
[
"id" : 1,
"team" : [
[
"name" : "John",
"job" : "teacher"
],
[
"name" : "Paul",
"job" : "coach"
],
[
"name" : "Mary",
"job" : "chef"
]
]
],
[
"id" : 7,
"team" : [
[
"name" : "Simon",
"job" : "engineer"
],
[
"name" : "Laura",
"job" : "writer"
],
[
"name" : "Peter",
"job" : "bartender"
]
]
],
[
"id" : 4,
"team" : [
[
"name" : "Igor",
"job" : "pianist"
],
[
"name" : "Mary",
"job" : "bartender"
],
[
"name" : "Denise",
"job" : "accountant"
]
]
]
]
I want to extract from the above array of dictionaries the element whose "team"
value (which itself is an array of dictionaries) has an element whose "job"
value is "writer".
In other words, for the purpose of this exercise, I want the 2nd element of the participants
array which is:
[
"id": 7,
"team": [
[
"name": "Simon",
"job": "engineer"
],
[
"name": "Laura",
"job": "writer"
],
[
"name": "Peter",
"job": "bartender"
]
]
]
How would I use map
and/or filter
to accomplish this?