// Assuming you have a Vue instance with data property named 'myArray'
new Vue({
data: {
myArray: []
},
methods: {
setArrayValueByKey(key, value) {
// Find the index of the item with the specified key in 'myArray'
const index = this.myArray.findIndex(item => item.key === key);
// If the item with the key exists, update its value
if (index !== -1) {
this.$set(this.myArray, index, { key, value });
} else {
// If the item with the key doesn't exist, push a new object to 'myArray'
this.myArray.push({ key, value });
}
}
}
});