I'm wondering if there is a way to clear or empty an array of objects, let's say for example i have this array of objects, which i borrow from firebase firestore, i do this with a snapshot, here is the code:
let siteButtonsData = firebase.firestore()
.collection('app_settings')
.doc('dashboard')
.collection('main_panel')
.onSnapshot(doc => {
doc.forEach(doc => {
this.arrObj.push(doc.data())
});
})
Then my array of objects is populated correctly, and it's shown like this:
data() {
return {
arrObj: [
{
action: 'one',
id: 1,
text: 'hello1'
},
{
action: 'two',
id: 2,
text: 'hello2'
},
{
action: 'three',
id: 3,
text: 'hello3'
},
]
}
}
With v-for i iterate over this.buttons to create some dynamic content in my app, but when something changes on my firestore database, and the snapshot updates it, i got duplicates, i was hoping to clear the array of objects before updating from firestore, so i would have no duplicates, but it's not working, so far i have tried:
this.arrObj = [{}]
this.arrObj = [] //This option leaves me with no way to push the array of objects
this.arrObj.length = 0
No matter which of this methods i use, i can't update correctly the array of objects, the first time it does the job well gathering the data from firestore, but once i update the database i got duplicates.
thanks in advance for any help or hint
arrObj = []orarrObj .length=0arrObj = [{}]? how is that different fromarrObj.length=0?arrObj.length=0removes all entries fromarrObj, whereasarrObj = [{}]overwrites the variable with an array containing a single empty object. All other references to the previousarrObjare not affected from this "update". It's basically the same as restoring your current car to look like new vs buying the same car again. Plus[{}]is not an empty array.