Hello I have been trying to find the highest value in my constantly changing array. What I need is to have an array that changes acording to input (which I have) and a table that shows the three highest values of that array and changes along with the array values. I used the Math.max, but I always get NaN as my answer. This is my code:
const array = [
Weighted1,
Weighted2,
Weighted3,
Weighted4,
Weighted5,
Weighted6,
Weighted7,
Weighted8,
Weighted9,
Weighted10,
Weighted11,
Weighted12,
];
const [First, setFirst] = useState("");
const [Second, setSecond] = useState("");
const [Third, setThird] = useState("");
/*
useEffect(() => {
setFirst(Math.max(array));
}, [array]);
useEffect(() => {
setSecond(array.splice(array.indexOf(one), 1), Math.max(array));
}, [array, one]);
useEffect(() => {
setThird(array.splice(array.indexOf(Second), 1));
}, [array, Second]);
*/
Mytable has these two tipes of values, one is the weighted (all those zeros) and the other is the names I want to be displayed depending on the weighted next to it. enter image description here
Math.max(...array), I think.