Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
how can I replace one single element in an array in ruby? so that an array
days=["monday", "tuesday", "wednesday", "jueves"] #so "jueves" gets replaced by the string "thursday"
thanks
days[3] = 'thurdsay'
You an also do...
days.map!{|day| day == "jueves" ? "thursday" : day}
m-p's answer will replace the first occurrence, this will replace all occurrences.
Add a comment
days[3] = "thursday"
Unless you want something more dynamic.
days[days.index("jueves")] = "thursday"
?
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
days[3] = 'thurdsay'?