Skip to content Skip to sidebar Skip to footer

Issue Storing Arrays In Sqlite Using Javascript

I've been using Cordova and the storage adapter for SQLite. When I store objects using JSON.stringify and the retrieve them they work. I also have several fields that are arrays, b

Solution 1:

I don't see any problem ,you can access initial array after parsing (JSON.parse(yourStringifiedArrayString)).

var yourarr=["test1", "test2", "test3"];
  var afterStringify = JSON.stringify(yourarr);
  console.log('After Stringify:'+afterStringify);
  var prevArr=JSON.parse(afterStringify);
  console.log('After Parsing:'+prevArr);
  //now access your arrayalert(prevArr[1]);//will show test2

Check Fiddle

Solution 2:

I don't see a problem with saving an array as a delimited string - It works fine for me. Just need to recreate the array using split() method when you retrieve it from SQLite.

Post a Comment for "Issue Storing Arrays In Sqlite Using Javascript"