简体   繁体   中英

How to save array of objects in localstorage

I have this array

在此处输入图片说明

I want set all keys and values in localstorage like this:

在此处输入图片说明

To do this you can loop through the array, calling localStorage.setItem() setting the key and val properties for every property in your array of objects. Something like this:

yourArray.forEach(o => localStorage.setItem(o.key, o.val));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM