How to create a single object from multiple arrays

95 Views Asked by At

I would like to get a single object that contains all the keys and values of the Localforage iteration function.

Reference: https://localforage.github.io/localForage/#data-api-iterate

 localforage.setItem("Dragon Ball", "Bulma").then(function(value) {
          console.log(value);
        });
    
        localforage.setItem("OnePiece", "Nami").then(function(value) {
          console.log(value);
        });
    
        localforage.iterate(function(value, key, iterationNumber) {
            console.log([key, value]);
      })
      .then(function() {
        //Get all in one Object
      });

Automatically translated

1

There are 1 best solutions below

0
On

Simply create an empty object outside its iterate function and then populate it with those key-values:

const data = {} // change the name properly

localforage.iterate(function(value, key, iterationNumber) {
 data[key] = value;
})