Sorting the results of an indexedDB query

Viewed 18941

I want to sort results obtained from indexedDB.
Each record has structure {id, text, date} where 'id' is the keyPath.

I want to sort the results by date.

My current code is as below:

  var trans = db.transaction(['msgs'], IDBTransaction.READ);
  var store = trans.objectStore('msgs');

  // Get everything in the store;
  var keyRange = IDBKeyRange.lowerBound("");
  var cursorRequest = store.openCursor(keyRange);

  cursorRequest.onsuccess = function(e) {
    var result = e.target.result;
    if(!!result == false){
        return;
    }
    console.log(result.value);
    result.continue();
  };
3 Answers
Related