how to find biggest value for particular array objects from nested array.
My Javascript Array:
JavaScript
x
54
54
1
const Application = [
2
{
3
chartData: [
4
{
5
title: "Type 1",
6
value: 60,
7
},
8
{
9
title: "Type 2",
10
value: 21,
11
},
12
{
13
title: "Type 3",
14
value: 4,
15
},
16
],
17
name: "App 1",
18
},
19
{
20
chartData: [
21
{
22
title: "Type 1",
23
value: 34,
24
},
25
{
26
title: "Type 2",
27
value: 45,
28
},
29
{
30
title: "Type 3",
31
value: 8,
32
},
33
],
34
name: "App 2",
35
},
36
{
37
chartData: [
38
{
39
title: "Type 1",
40
value: 59,
41
},
42
{
43
title: "Type 2",
44
value: 1,
45
},
46
{
47
title: "Type 3",
48
value: 3,
49
},
50
],
51
name: "App 3",
52
},
53
];
54
I want to find the maximum value of the nested chartData array.
I want a method to calculate the maximum value and for the above data the output should be 60.
Can anyone help ?
Advertisement
Answer
you can use this way:
JavaScript
1
10
10
1
const maxValue = Math.max.apply(
2
Math,
3
Application.map((e) => {
4
return e.chartData.map((el) => {
5
return el.value
6
})
7
})
8
) //[60,21,4,34,45,8,59,1,3]
9
console.log(maxValue) //60
10