I wanted to store objects from indexDB into an array. But I cant access to objects. It always results in undefined. I even tried converting to JSON before storing on indexDB and parsing when retrieving. Nothing seems to work.
indexDB
function getFromDB() { // Open let openRequest = indexedDB.open("TestDB", 1); let db; let x = []; openRequest.onerror = function () { console.log("Error Opening DB"); }; openRequest.onsuccess = function () { db = openRequest.result; let readRequest = db .transaction(["Jobs"], "readwrite") .objectStore("Jobs") .openCursor(); readRequest.onerror = function () { console.log("Error Reading"); }; readRequest.onsuccess = function (e) { let cursor = e.target.result; if (cursor) { x.push(cursor.value); cursor.continue(); } }; }; console.log(x); } getFromDB(); });
2.1m questions
2.1m answers
60 comments
57.0k users