You can create an array with ones using the Array.fill()
method in JavaScript. Here's an example:
index.tsx110 chars4 lines
In this example, we first create a new array with a length of 5 by passing the value 5
to the Array()
constructor. We then call the fill()
method on the array and pass in the value 1
. This sets all elements in the array to 1
, resulting in an array containing 5 ones.
gistlibby LogSnag