简体   繁体   中英

How to create a single object from multiple arrays

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

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;
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM