Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript - Saving 2d Array to Local Storage and retrieving

I have a two-dimensional array holding information which I need to save to local storage and then retrieve later. Here is my data:

var content_array = [
    ["0","Mobile Application Development","CT5006","01/14/2013","Note"],
    ["1","Java Programming","CT5005","01/16/2013","Note"],
    ["2","Multimeida Application Development","CT5011","02/13/2013","Note"]
];

Any easy way to turn this into a string then back into a 2D array?

like image 590
James W. Avatar asked May 30 '26 07:05

James W.


1 Answers

Use the native JSON.stringify method:

var str = JSON.stringify(content_array);

You can then use the JSON.parse method to get it back into an actual array:

var content_array = JSON.parse(str);
like image 163
James Allardice Avatar answered Jun 01 '26 21:06

James Allardice