Hello StackOverflowCommunity! My name is Piet.
While investigating the beloved Javascript I got a bit stuck:
I´m not sure why I get 98 empty items pushed into my Array.
On Index[0] and Index[99] I get IntegerValues as expected.
Thank you for your answers! :)
// create an Array with the size of N(x) and
// fill it with numbers in a range from 0 to 100 randomly.
createNSizedArray = (x) => {
for(let i = 0; i < x; i++) {
var arr = [];
arr[i] = arr.push(Math.round(Math.random()*100));
}
return arr;
}
console.log(createNSizedArray(100));
// output -> [ 31, <98 empty items>, 1 ];
// Why are the other 98 items in the Array empty and how to change them into integer values?
Actually I inspected the Items[1-98] to find out their values and to check if they are really empty.
But:
console.log(arr[4]) for example return "undefined" to me. So they are not really empty.