I am receiving in a function an array with defined values and others to be defined.
["y", null, null, null, null, null, null, null, null]
What I am trying to do is that every time I receive this array I check the values that are at null and to one of them, chosen in a random way, I want to set the value "Z" and return the array modified.
For this I am doing the following in my function:
nextValue(array) {
const random = Math.floor(Math.random() * array.length);
}
};
At this point , which I have found in other references , if I print the value "random = Nan" and "array[random] = undefined".
How could I modify the value ?
Would there be a better method without the need to extract the value, and modify it directly?