-2

I have an array of arrays called Lines

Numbers = [[1,2,3],[4,5,6],[7,8,9]]

and var numberInt = 10

how do i append this numberInt inside the last array of the multidimensional array? so it would look like

Numbers = [[1,2,3],[4,5,6],[7,8,9,10]]

Thank you.

David Robertson
  • 1,561
  • 4
  • 19
  • 41

1 Answers1

3

Use Numbers[Numbers.count - 1] to get last one-dimensional array and append method to add item:

Numbers[Numbers.count - 1].append(numberInt)
print(Numbers) // prints "[[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]"

I'd also recommend you to take a look at this answer: https://stackoverflow.com/a/25128237/1796907

Community
  • 1
  • 1
egor.zhdan
  • 4,555
  • 6
  • 39
  • 53