I've been utilizing Ionic 2 Storage to store form data persistently. The method I use for saving the data is as follows:
this.storage.set(key, JSON.stringify(formData));
When it comes to retrieving and updating the stored data, here's what I do:
this.getReport(key).then((report) => {
var objReport = JSON.parse(report);
objReport.push(data); //this is where the issue arises
this.storage.set(pk, JSON.stringify(objReport));
});
The getReport function looks like this:
getReport(key) {
return this.storage.get(key);
}
Although I'm aware that .push is meant for arrays and not objects, constantly converting between them isn't ideal due to the size of the objects I'm working with.
So my question is: What would be the most efficient approach to retrieve JSON from storage and append to it? It seems illogical to me that .parse returns an object when objects lack a push method similar to arrays.
Here's the error I'm encountering:
Runtime Error Uncaught (in promise): TypeError: Cannot read property 'push' of undefined TypeError: Cannot read property 'push' of undefined