I would like to create a new array B_array
based on an existing array A A_array
. If that item in A_array
has a certain field then add it into B_array
.
Currently this is what I have and its putting everything into B_array
:
B_array = A_array.map {|item| if item.name == 'Josh'}
A_array:
[id:0,name:"Josh",email:"josh@josh@gmail.com"],
[id:1,name:"Scott",email:"scott@josh@gmail.com"],
[id:2,name:"Josh",email:"dan@josh@gmail.com"]
Desired output for B_array
:
[id:0,name:"Josh",email:"josh@josh@gmail.com"],
[id:2,name:"Josh",email:"dan@josh@gmail.com"]
Thanks!