- 18
- Posts
- 7
- Years
- Age 26
- California
- Seen Jan 29, 2023
Hello, I've been having trouble trying to push variables in 2 dimensional arrays. I don't even know if this is possible.
The first thing I do is initialize the array like so:
Next, I have two other variables, for example:
So what I'm trying to do is to push the array that is inside the array.
However, this isn't working. Can you use the push function in 2 dimensional arrays? Or is the problem elsewhere?
The first thing I do is initialize the array like so:
Code:
array2=Array.new(3){Array.new}
Next, I have two other variables, for example:
Code:
var1=3
var2=rand(10)
So what I'm trying to do is to push the array that is inside the array.
Code:
for x in 0...var1
for i in 0...var2
array2[x].push[i]=rand(50)
end
end
However, this isn't working. Can you use the push function in 2 dimensional arrays? Or is the problem elsewhere?