Updating Array Values

Updating Arrays Values

  • You can change a value in an array by referencing the value and then changing the value using an = (equal sign)

Example

// declare a variable called newEditionMembers and use it to store
// an array of names

const newEditionMembers = ["Ricky Bell", "Michael Bivins", "Bobby Brown", "Ronnie DeVoe", "Ralph Tresvant"]

// We are going replace Bobby Brown with Johnny Gill
// by referencing the 3rd element of the array by using index 2
// and then use assignment (just an equal sign) to change
// the value to Johnny Gill

newEditionMembers[2] = "Johnny Gill"

JS Bin on jsbin.com