typescript - Saving an array of objects in localStorage -
i'm trying add item localstorage array make array of objects , iterate somewhere in angular 2 app. how i'm trying save localstorage item:
if (!this.search_history) { localstorage.setitem('search_history', json.stringify(this.calc)); } else { localstorage.setitem('search_history', this.search_history + ',' + json.stringify(this.calc)); }
and in component i'm trying iterate:
private searchhistory = json.parse(localstorage.getitem('search_history')) || [];
i go confused how supposed work, think have problem way trying insert new array item. not sure if can use push in case.
what's proper syntax insert new array record?
Comments
Post a Comment