If I have the following arr = [13,12,31,31]
Now say I want to push in another set of numbers like 12,13,54,32
So I can do arr << [12,13,54,32]
but now I have [13,12,31,31,[12,13,54,32]]
So how can I remove the outside array? arr = arr.pop
works sometimes but I'm guessing that a better way exists. Please enlighten.
Don't use <<
, use +
arr = [13,12,31,31]
arr += [12,13,54,32]
# arr => [13,12,31,31,12,13,54,32]
You should use Array#flatten
[[13,12,31,31,12,13,54,32]].flatten # => [13, 12, 31, 31, 12, 13, 54, 32]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With