I have an array of objects which I am using a for/in loop to manipulate into key/value pairs, which as it works writes each to a database.
My app is designed to send a push notification when the database is updated, which works as intended, but when there are multiple items in the loop it will send a notification per each of these objects (expected, but not so intended)
My simple loop code is:
for(var idx in multiSelectSaveArr) {
calendarPage.saveCalendarMultiItem(time = multiSelectSaveArr[idx].creationDate, multiSelectSaveArr[idx])
}
The purpose of this is that time
will become the unique key, whilst the value is a JSON object.
my calendarPage.saveCalendarMultiItem
is a signal to my dataModel, which is where the function to store the data is, so each iteration then calls a function which handles the database writing as an individual object
The nature of my loop is that sometimes it could contain 3 objects, other times 30 - it is a different number each time.
My Question Is
Is there a way I can signal the end of the loop, meaning once the final object has been iterated through to then only send a single notification?
Thanks for any help!