user2828442
user2828442

Reputation: 2515

How can i save and fetch array values in local storage

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

Answers (1)

Sajeetharan
Sajeetharan

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

Related Questions