Step 18: Array Update

We can use bracket syntax similar to that shown above to get items at particular indices to update items at particular indices.

best_programming_languages = ["C++", "Go", "Scala", "JavaScript", "Python"]
best_programming_languages[2] = "Ruby"

ind = 0

while ind < best_programming_languages.length
    if best_programming_languages[ind] != "Ruby"
        best_programming_languages[ind] = "Ruby"
    ind = ind + 1


Here we also introduced a new method: .inspect. In the previous example, we saw that if we use .puts on an array, it will print out each item of the array individually. .inspect makes our lives a lot easier here because it allows us to print out the array as an array instead of each item individually.