문제

Can any object be stored in a DOM Storage?

When I do the following:

// where val is a string and response is an array of objects.
sessionStorage.results= { val: response };

When I inspect value of sessionStorage.results I get "[object Object]"

Can I store objects like that? Or does Storage only stores strings?

도움이 되었습니까?

해결책

You can only store strings in any type of (DOM-)storage. To store data objects (plain: no circular references, no special constructors) you can convert them to JSON and back from a string to restore them. See also this answer (improvement).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top