3 years ago

Properly remove object from map/object

Posted 3 years ago by miso

Hi, I have

// data structure in vue object
data: {
    records: null
// loading the records:
var map = {};
for (var i = 0; i < response.data.length; i++) {
    map[response.data[i].record_id] = response.data[i];
this.records = map;

I want to remove object from this.records[k]. The code below works so far, but I am not sure if this is correct because the two operations are not atomic. Could it throw error when this.records are used in v-for?

this.records[record_id] = null; // this will notify the watcher
delete this.records[record_id]; // this will remove key and value from the map/object.

What is the best practice for this? Thank you

Please sign in or create an account to participate in this conversation.