[Vuejs]-Migrate IndexedDB data to an array in JS

0👍

You need to set app.tasks[i] to an empty object at the beginning of each assignment in the loop:

    transferDBtoArray() {
        db.tasks.where('name').noneOf().toArray(function(result) {
            for(var i= 0; i< result.length; i++) {
                app.tasks[i] = {};
                app.tasks[i].id = result[i].id;
                app.tasks[i].name = result[i].name;
                app.tasks[i].str = result[i].str;
                app.tasks[i].int = result[i].int;
                app.tasks[i].vit = result[i].vit;
                app.tasks[i].agi = result[i].agi;
                
            }
        });

Or better yet:

transferDBtoArray() {
  db.tasks.where('name').noneOf().toArray(results => results.map(result => ({          
        id: result.id,
        name: result.name,
        str: result.str,
        int: result.int,
        vit: result.vit,
        agi: result.agi,
  })));

Leave a comment