If I type c.messages.reverse.delete_at(0) nothing happens, where messages is the array. If I type c.messages.delete_at(0) it deletes the first element as it should. Why does this not work with reverse?
If I type c.messages.reverse.delete_at(0) nothing happens, where messages is the array. If I type
Share
That happens because
reversereturns a new array, of which you are deleting the last member. You could usereverse!, which mutates the original array.If you want to remove the last element from an array, the best way would be to use
pop.