Search code examples
ruby-on-railsruby-on-rails-5

Remove elements from array based on value in rails


arr = ['Jack', 'Ross', 'Buggi', 'Mimi', 'Zolo', 'Roy']

From this array if want to remove certain values like lets say Buggi and Zolo, how can I do that so that the arr looks something like

arr = ['Jack', 'Ross', 'Mimi', 'Roy']

Buggie and Zolo are just examples, it can be any element Ross, Roy.

I want to implement this in rails.


Solution

  • I suggest using arr.filter() with a block that defines the defines the items you want to keep.