Linked Questions

Popular Questions

If I have an array with five empty arrays inside of it i.e.

`5_empty_arrays = [[], [], [], [], []]`

how would I insert a name into the 1st array of the overall array i.e.

`[["Dean"], [], [], [], []]`


I can currently get

`5_empty_arrays.insert[0, "Dean"]`

`[["Dean"], [], [], [], [], []]`

but that adds an extra array it doesn't insert into the 1st array.

I followed the advice of Steen slag and made the changes to my existing code but I now get "Dean" printed in every element. However, when I manually create the array of arrays as Steen slag did it works as predicted. Any idea? Thanks!

number_of_groups = 5

array = []
array = array.push([])* number_of_groups
array[0] << "Dean"
p array

=> [["Dean"], ["Dean"], ["Dean"], ["Dean"], ["Dean"]]

Related Questions