-1

I have the arrangement within an arrangement that is as follows:

data = [
  [{
    :devicetotal => "ACH-EPN-AN01",
    :porttotal => "to_BTS IP-CAC HUARAZ - TAI5670",
    :queueIdtotal => "3",
    :device_int_stats_total => "ACH-EPN-AN01to_BTS IP-CAC HUARAZ - TAI56703",
    :timeCapturedtotal => "March 15, 2018 at 07:06 PM",
    :discard_sub => 0
  }],
  [{
    :devicetotal => "ACH-EPN-AN01",
    :porttotal => "to_BTS IP-CAC HUARAZ - TAI5670",
    :queueIdtotal => "6",
    :device_int_stats_total => "ACH-EPN-AN01to_BTS IP-CAC HUARAZ - TAI56706",
    :timeCapturedtotal => "March 15, 2018 at 07:06 PM",
    :discard_sub => 0
  }]
]

How do I have the following format?

data = [{
  :devicetotal => "ACH-EPN-AN01",
  :porttotal => "to_BTS IP-CAC HUARAZ - TAI5670",
  :queueIdtotal => "3",
  :device_int_stats_total => "ACH-EPN-AN01to_BTS IP-CAC HUARAZ - TAI56703",
  :timeCapturedtotal => "March 15, 2018 at 07:06 PM",
  :discard_sub => 0
}, {
  :devicetotal => "ACH-EPN-AN01",
  :porttotal => "to_BTS IP-CAC HUARAZ - TAI5670",
  :queueIdtotal => "6",
  :device_int_stats_total => "ACH-EPN-AN01to_BTS IP-CAC HUARAZ - TAI56706",
  :timeCapturedtotal => "March 15, 2018 at 07:06 PM",
  :discard_sub => 0
}]

I used the following code but I get an error.

data2 = Array.new []
data.each do |traf_sub|
  data2 << traf_sub[1]
end
2
  • Please edit the question to make it readable without a horizontal scrolling. Commented Mar 16, 2018 at 18:46
  • The problem is that you're trying to access index 1 on an array that only has one element. This is also why you should post error messages. Commented Mar 16, 2018 at 18:57

1 Answer 1

0

use flatten

data.flatten
#=>  [{:devicetotal=>"ACH-EPN-AN01", :porttotal=>"to_BTS IP-CAC HUARAZ - TAI5670", :queueIdtotal=>"3", :device_int_stats_total=>"ACH-EPN-AN01to_BTS IP-CAC HUARAZ - TAI56703", :timeCapturedtotal=>"March 15, 2018 at 07:06 PM", :discard_sub=>0}, {:devicetotal=>"ACH-EPN-AN01", :porttotal=>"to_BTS IP-CAC HUARAZ - TAI5670", :queueIdtotal=>"6", :device_int_stats_total=>"ACH-EPN-AN01to_BTS IP-CAC HUARAZ - TAI56706", :timeCapturedtotal=>"March 15, 2018 at 07:06 PM", :discard_sub=>0}]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.