The first argument is the value you want to fill the array with, it can range from a string to an number to to even another array.
The second argument is the index of the array in which you want to start filling the array from. If you do this Array(5).fill(3, 2). This means you want to fill the array from index 2 till the end with the value if 3. This will return [undefined, undefined, 3, 3, 3]
The third argument is the index position of the array in which you want to stop filling the array. Array(5).fill(3, 2, 4) will give you this [undefined, undefined, 3, 3, undefined].
Array.of() doesn't return undefined for numbers.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
A newbie is confused...
Why is array().fill and array.of returning undefined for numbers?
Hi @aphatheology
Array.fill()
takes three arguments.The first argument is the value you want to fill the array with, it can range from a string to an number to to even another array.
The second argument is the index of the array in which you want to start filling the array from. If you do this
Array(5).fill(3, 2)
. This means you want to fill the array from index 2 till the end with the value if 3. This will return[undefined, undefined, 3, 3, 3]
The third argument is the index position of the array in which you want to stop filling the array.
Array(5).fill(3, 2, 4)
will give you this[undefined, undefined, 3, 3, undefined]
.Array.of()
doesn't return undefined for numbers.