-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
48 lines (46 loc) · 948 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
sections = [
{
"id": 5,
"lines": [
{
"id": 3,
"description": "Line description",
"snippet": "line snippet",
"section": 5
},
{
"id": 4,
"description": "Line description2",
"snippet": "line snippet2",
"section": 5
}
],
"title": "Section title",
"description": "Section description",
"cheatsheet": 21
},
{
"id": 6,
"lines": [
{
"id": 5,
"description": "Line description",
"snippet": "line snippet",
"section": 5
},
{
"id": 6,
"description": "Line description2",
"snippet": "line snippet2",
"section": 5
}
],
"title": "Section title",
"description": "Section description",
"cheatsheet": 21
}
]
let a = sections.reduce((acc, cur) => {
return acc.concat(cur.lines)
}, []).find((line) => line.id === id)
console.log(a)