Reputation: 2515
I am able to save an array as shown below:
list: Array<number> = [1, 2, 3];
but I wish to save a bit more complicated case like:
[{name:"saurabh" , age: 5 , sex:"male"}];
Now how do I do that?
Upvotes: 1
Views: 253
Reputation: 222592
You can use JSON.stringify
and call setItem
let myArray = [{name:"saurabh" , age: 5 , sex:"male"}];
localStorage.setItem('userCache', JSON.stringify(myArray));
Upvotes: 5