简体   繁体   中英

How to Store Multi-Dimensional Array in Phonegap

I am trying to store a multi dimensional (2 dimension) array in JavaScript phonegap using localstorage.setitem

However, it seems to convert the array into a single dimension.

Is there any way to maintain the array structure when stored locally?

Thanks.

I had the same problem and I used the following solution to make it work:

var a1 = [1,2,3];
var b1 = [4,5,6];
var c1 = [7,8,9];
var a = [a1, b1, c1];
localStorage.setItem("arr", JSON.stringify(a));
var b = JSON.parse(localStorage.getItem("arr"));

By default, localStorage only supports strings as storage formats. You can't store results of JavaScript computations that are arrays or objects, and every number is stored as a string - http://24ways.org/2010/html5-local-storage .

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