I get the following error in Typescript:
Argument of type 'number[]' is not assignable to parameter of type 'number'
I get the max value of array without the below error:
analysis_horizon_array_test: number[] = [];
this.analysis_horizon_array_test.push(1)
console.log(Math.max(this.analysis_horizon_array_test));
How do I get the max value of an array without throwing an error? It does work though.
Math.max
takes individual numbers, not an array. You can use spread syntax if you're compiling to a supported target, otherwise you have to use apply
:
console.log(Math.max(...this.analysis_horizon_array_test));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With