'How to combine 2 array

I have 2 arrays of objects, I want to combine both array of objects as one array, by adding 2nd arrays key value pair as 3rd key value pairs for 1st array.

First array

 a = [{:performed_at=>"Aging", :result=>"Not Completed"}, {:performed_at=>"Aging", :result=>"Not Completed"}, {:performed_at=>"Mar 25, 2022", :result=>"Pass"}]

Second Array

b = [{:line_item=>"10C-1648150055"}, {:line_item=>"10D-1648150055"}, {:line_item=>"10E-1648150055"}]

I want the result array of objects like this

[{:performed_at=>"Aging", :result=>"Not Completed", :line_item=>"10C-1648150055"}, {:performed_at=>"Aging", :result=>"Not Completed",:line_item=>"10D-1648150055"}, {:performed_at=>"Mar 25, 2022", :result=>"Pass",:line_item=>"10E-1648150055"}]

Kindly help



Solution 1:[1]

Something like the this should work:

a.map.with_index do |el, index|
 el.merge(b[index])
end

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 markets