A. Ilazi A. Ilazi - 1 month ago 10
Javascript Question

Firebase: How to update arrays length when manually delete one path?

On my website a user can enter multiple addresses. The file structure looks like this:

enter image description here

I load the data to the users profile so that he can change it and add different cities if needed. To do that I loop through each address in a for-loop. For that purpose I need the correct length of address. But since address is an array after deleting one address the length still stays at two.

What options do I have?

Thank you

Answer

You should use Push method of Firebase instead of saving data in arrays

var ref=firebase.databae().ref("user/"+uid+"/address");
ref.push({city:"ABC",houseNo:"444",postalCode:"3433",street:"street"});

Firebase Save Data

Why to avoid arrays,please check Best Practice for Arrays