[Solved] delete values from an array in an object using JavaScript?


You need to specify how many items you want to splice (1 I guess assuming the name is singular) Otherwise it would remove all the messages to the end starting the index.

var facebookProfile = {
  messages: ["hi", "bye", "test"],
  deleteMessage: function deleteMessage(index) {
     facebookProfile.messages.splice(index, 1);
  },
}

facebookProfile.deleteMessage(1)
console.log(facebookProfile.messages)

facebookProfile.deleteMessage(1)
console.log(facebookProfile.messages)

1

solved delete values from an array in an object using JavaScript?