I have an below array with elements.
Array [
0,
0,
0,
0,
0,
0,
0,
4116.38,
4120.87,
0,
0,
0,
]
How can i filter all the "0" value and the maximum value from the array?
I have an below array with elements.
Array [
0,
0,
0,
0,
0,
0,
0,
4116.38,
4120.87,
0,
0,
0,
]
How can i filter all the "0" value and the maximum value from the array?
You don't, you just use const maxInYourArray = Math.max(...yourArray)
, relying on modern spread syntax to turn your array into distinct arguments, because the Math.max function can take an arbitrary number of values as function arguments and returns the maximum value amongst them.
The same applies to Math.min
, but that will obviously give you 0
, so if you want to ignore all those zeroes, filter them out first: const minInYourArray = Math.min(...yourArray.filter(v => v!==0))