vendredi 17 février 2017

How to reset array indexes in JavaScript array

I'm using React & Firebase database for web.

In the below code, dbRef points to a Firebase database tree containing an array of strings. Some of this array's elements have been removed which has resulted in null indexes.

[
  "0": "first",
  "1": "next",
  "6": "skipped indexes 2 - 5"
]

I'm currently doing:

dbRef.set([...currentList, newItem])

However, I'd like to ensure that the array passed to set does not have any null indexes. What is the best way to do this in JS? (I'm using babel if it matters)

Aucun commentaire:

Enregistrer un commentaire