Cut array after key in Ruby -


i need cut array after key in ruby, example:

=> ["foo", "bar", "baz", "oof", "rab", "zab"] # cut after "baz" => ["baz", "oof", "rab", "zab"] # result 

it's possible do? how can that?

yes, specify range index -1(last element):

arr = ["foo", "bar", "baz", "oof", "rab", "zab"] arr[arr.index("baz")..-1] # =>  ["baz", "oof", "rab", "zab"] 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -