jStorage icon indicating copy to clipboard operation
jStorage copied to clipboard

Best practice for setting value of nested objects?

Open bcamp1973 opened this issue 11 years ago • 1 comments
trafficstars

our data is nested a few layers deep. i've been using the following approach to save changes to nested values, but it feels sloppy. is there a better way?

$.jStorage.get('data')['authors'][33]['books'][5]['title'] = 'See Spot Run';

bcamp1973 avatar Jan 07 '14 18:01 bcamp1973

That code would not save the value, just copy it with an updated deep value.

To save you would need to...

var data = $.jStorage.get('data');
data.authors[33].books[5].title = 'See Spot Run';
$.jStorage.set('data', data);

doublejosh avatar Aug 12 '15 05:08 doublejosh