arrays - Retrieving all localstorage data in a format that can be useful in javascript -
i doing uni assignment , part requires me pull data multiple localstorage keys , compile them in various ways (add them basically.) have got data stored form array in following format
testname;testcompany;6192742222;email@email.com;1 john st;;bellevue;6056; ;5;10;20.00;44;64.00;6.40;70.40;
now may have multiple of these , need take few of them, figures towards end, , add them variable number of other values other strings , hitting head against wall trying figure out.
also because uni assignment cannot use jquery
, json
or server based software.
edit: after doing suggested below still having issues, cannot th life of me code format in comments section figured put here.
window.onload = getallitems(); function getallitems() { var = 0; var lslength = localstorage.length-1; (i = 0; <= lslength; i++) { var itemkey = localstorage.key(i); var values = localstorage.getitem(itemkey); var values2 = values.split(";"); function extract(values2) { var result = {}; result.name = values2[0]; // ... result.email = values2[3]; // ... return result; }}}
if format of value stored in localstorage
this
testname;testcompany;6192742222;email@email.com;1 john st;;bellevue;6056; ;5;10;20.00;44;64.00;6.40;70.40;
then do
// suppose retrieved string localstorage , have in // variable called data var dataarray = data.split(';');
then write function maps position in array name object, easier later manipulate it, example like:
function extract(arraydata) { var result = {}; result.name = arraydata[0]; // ... result.email = arraydata[3]; // ... return result; }
Comments
Post a Comment