How to list objects including value, name, denomination?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I have an object like this:



  var currencyTypes = {
NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
USD: {value:0.12652, name: "United States dollar", denomination: "$" },
GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
};


And I have found a way to list all the key objects:



var keyVal = ;
for(var v in currencyTypes) keyVal.push(v);

"There are " + keyVal.length + " different currencies here: " + keyVal


This lists all the currencyTypes: NOK,EUR, USD, GBP



But how can I print a list with key, value, name, denominations? I tried keyVal.properties but that didn’t work. I've tried to search for a solution here, but haven't found anything. What I want is an output that looks something like this:



NOK, Norske kroner, 1 kr
EUR, European euros, 0.10733 €
and so on









share|improve this question





























    0















    I have an object like this:



      var currencyTypes = {
    NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
    EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
    USD: {value:0.12652, name: "United States dollar", denomination: "$" },
    GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
    };


    And I have found a way to list all the key objects:



    var keyVal = ;
    for(var v in currencyTypes) keyVal.push(v);

    "There are " + keyVal.length + " different currencies here: " + keyVal


    This lists all the currencyTypes: NOK,EUR, USD, GBP



    But how can I print a list with key, value, name, denominations? I tried keyVal.properties but that didn’t work. I've tried to search for a solution here, but haven't found anything. What I want is an output that looks something like this:



    NOK, Norske kroner, 1 kr
    EUR, European euros, 0.10733 €
    and so on









    share|improve this question

























      0












      0








      0








      I have an object like this:



        var currencyTypes = {
      NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
      EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
      USD: {value:0.12652, name: "United States dollar", denomination: "$" },
      GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
      };


      And I have found a way to list all the key objects:



      var keyVal = ;
      for(var v in currencyTypes) keyVal.push(v);

      "There are " + keyVal.length + " different currencies here: " + keyVal


      This lists all the currencyTypes: NOK,EUR, USD, GBP



      But how can I print a list with key, value, name, denominations? I tried keyVal.properties but that didn’t work. I've tried to search for a solution here, but haven't found anything. What I want is an output that looks something like this:



      NOK, Norske kroner, 1 kr
      EUR, European euros, 0.10733 €
      and so on









      share|improve this question














      I have an object like this:



        var currencyTypes = {
      NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
      EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
      USD: {value:0.12652, name: "United States dollar", denomination: "$" },
      GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
      };


      And I have found a way to list all the key objects:



      var keyVal = ;
      for(var v in currencyTypes) keyVal.push(v);

      "There are " + keyVal.length + " different currencies here: " + keyVal


      This lists all the currencyTypes: NOK,EUR, USD, GBP



      But how can I print a list with key, value, name, denominations? I tried keyVal.properties but that didn’t work. I've tried to search for a solution here, but haven't found anything. What I want is an output that looks something like this:



      NOK, Norske kroner, 1 kr
      EUR, European euros, 0.10733 €
      and so on






      javascript object






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 14:37









      SenselessSenseless

      427




      427
























          6 Answers
          6






          active

          oldest

          votes


















          1














          You can access it this way. This might help you.






           var currencyTypes = {
          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
          };

          for(var type in currencyTypes)
          {
          console.log("Currency: " + type);

          console.log("Value: " + currencyTypes[type].value);
          console.log("Name: " + currencyTypes[type].name);
          console.log("Denomination: " + currencyTypes[type].denomination);

          console.log("n");
          }








          share|improve this answer































            1

















            const currencyTypes = {
            NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
            EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
            USD: {value:0.12652, name: "United States dollar", denomination: "$" },
            GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
            };

            function compileCurrenciesString(currencies) {
            let outStr = '';
            Object.keys(currencies).forEach((key) => {
            outStr += currencyToString(key, currencies[key]);
            outStr += 'n';
            });
            return outStr;
            }

            function currencyToString(key, currency) {
            return `${key}, ${currency.name}, ${currency.value} ${currency.denomination}`;
            }

            console.log(compileCurrenciesString(currencyTypes));








            share|improve this answer































              0














              You could use Object.keys(currencyTypes) to retrieve all of an objects keys, and then loop over those:






              const currencyTypes = {
              NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
              EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
              USD: {value:0.12652, name: "United States dollar", denomination: "$" },
              GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
              };

              Object.keys(currencyTypes).forEach(k => console.log(
              `${k}, ${currencyTypes[k].name}, ${currencyTypes[k].value} ${currencyTypes[k].denomination}`
              ));








              share|improve this answer































                0














                You could use for...of loop with Object.entries to get key value.






                var currencyTypes = { NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" }, EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" }, USD: {value:0.12652, name: "United States dollar", denomination: "$" }, GBP: {value:0.09550, name: "Pound sterling", denomination: "£" }};

                for([key, {name, value, denomination}] of Object.entries(currencyTypes)) {
                let str = `${key}, ${name}, ${value} ${denomination}`
                console.log(str)
                }








                share|improve this answer































                  0














                  If you're coding to the ES6 spec then you can use destructuring assignment.



                  I also utilize Object.entries method to turn the object properties into an array of key value entry pairs - then iterate over that with Array.prototype.forEach.






                  var currencyTypes = {
                  NOK: {
                  value: 1.00000,
                  name: "Norske kroner",
                  denomination: "kr"
                  },
                  EUR: {
                  value: 0.10733,
                  name: "Europeiske euro",
                  denomination: "€"
                  },
                  USD: {
                  value: 0.12652,
                  name: "United States dollar",
                  denomination: "$"
                  },
                  GBP: {
                  value: 0.09550,
                  name: "Pound sterling",
                  denomination: "£"
                  },
                  };

                  Object.entries(currencyTypes).forEach(entry => {
                  const [key, val] = entry;
                  const {
                  value,
                  name,
                  denomination
                  } = val;
                  console.log(`${key}n${value}n${name}n${denomination}`);
                  });








                  share|improve this answer































                    0














                    If you represent your collection as an array, it'll becomes easier to do this kind of things:






                    const currencyTypes = [
                    { "ticker": "NOK", "value":1.00000, "name": "Norske kroner", "denomination": "kr" },
                    { "ticker": "EUR", "value":0.10733, "name": "Europeiske euro", "denomination": "€" },
                    { "ticker": "USD", "value":0.12652, "name": "United States", "denomination": "$" },
                    { "ticker": "GBP", "value":0.09550, "name": "Pound sterling", "denomination": "£" }
                    ];
                    // Amount of currencies:
                    console.log( 'There are ' + currencyTypes.length + ' currencies in the array' );
                    // Array of all currency tickers:
                    console.log( currencyTypes.map( currency => currency.ticker ));
                    // Console.logging all of them:
                    currencyTypes.forEach( currency => console.log( currency ));
                    // Console.logging the properties using destructuring:
                    currencyTypes.forEach(({ ticker, value, name, denomination }) => console.log( ticker, value, name, denomination ));





                    When you have multiples of something, arrays are usually the easiest way since most objects representing collections can be created from the array in one line of code.



                    If you want to stay with using an object, look at Object.keys(), Object.values() and Object.entries(). Those will do alot of the converting back and forth from objects to arrays.



                    The function you coded to get the amount of keys in the object, basically is the same as Object.keys():






                    const currencyTypes = {
                    NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                    EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                    USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                    GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                    };

                    console.log( 'there are ' + Object.keys( currencyTypes ).length + ' currencies' );








                    share|improve this answer


























                      Your Answer






                      StackExchange.ifUsing("editor", function () {
                      StackExchange.using("externalEditor", function () {
                      StackExchange.using("snippets", function () {
                      StackExchange.snippets.init();
                      });
                      });
                      }, "code-snippets");

                      StackExchange.ready(function() {
                      var channelOptions = {
                      tags: "".split(" "),
                      id: "1"
                      };
                      initTagRenderer("".split(" "), "".split(" "), channelOptions);

                      StackExchange.using("externalEditor", function() {
                      // Have to fire editor after snippets, if snippets enabled
                      if (StackExchange.settings.snippets.snippetsEnabled) {
                      StackExchange.using("snippets", function() {
                      createEditor();
                      });
                      }
                      else {
                      createEditor();
                      }
                      });

                      function createEditor() {
                      StackExchange.prepareEditor({
                      heartbeatType: 'answer',
                      autoActivateHeartbeat: false,
                      convertImagesToLinks: true,
                      noModals: true,
                      showLowRepImageUploadWarning: true,
                      reputationToPostImages: 10,
                      bindNavPrevention: true,
                      postfix: "",
                      imageUploader: {
                      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                      allowUrls: true
                      },
                      onDemand: true,
                      discardSelector: ".discard-answer"
                      ,immediatelyShowMarkdownHelp:true
                      });


                      }
                      });














                      draft saved

                      draft discarded


















                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339924%2fhow-to-list-objects-including-value-name-denomination%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown

























                      6 Answers
                      6






                      active

                      oldest

                      votes








                      6 Answers
                      6






                      active

                      oldest

                      votes









                      active

                      oldest

                      votes






                      active

                      oldest

                      votes









                      1














                      You can access it this way. This might help you.






                       var currencyTypes = {
                      NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                      EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                      USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                      GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                      };

                      for(var type in currencyTypes)
                      {
                      console.log("Currency: " + type);

                      console.log("Value: " + currencyTypes[type].value);
                      console.log("Name: " + currencyTypes[type].name);
                      console.log("Denomination: " + currencyTypes[type].denomination);

                      console.log("n");
                      }








                      share|improve this answer




























                        1














                        You can access it this way. This might help you.






                         var currencyTypes = {
                        NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                        EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                        USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                        GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                        };

                        for(var type in currencyTypes)
                        {
                        console.log("Currency: " + type);

                        console.log("Value: " + currencyTypes[type].value);
                        console.log("Name: " + currencyTypes[type].name);
                        console.log("Denomination: " + currencyTypes[type].denomination);

                        console.log("n");
                        }








                        share|improve this answer


























                          1












                          1








                          1







                          You can access it this way. This might help you.






                           var currencyTypes = {
                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                          };

                          for(var type in currencyTypes)
                          {
                          console.log("Currency: " + type);

                          console.log("Value: " + currencyTypes[type].value);
                          console.log("Name: " + currencyTypes[type].name);
                          console.log("Denomination: " + currencyTypes[type].denomination);

                          console.log("n");
                          }








                          share|improve this answer













                          You can access it this way. This might help you.






                           var currencyTypes = {
                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                          };

                          for(var type in currencyTypes)
                          {
                          console.log("Currency: " + type);

                          console.log("Value: " + currencyTypes[type].value);
                          console.log("Name: " + currencyTypes[type].name);
                          console.log("Denomination: " + currencyTypes[type].denomination);

                          console.log("n");
                          }








                           var currencyTypes = {
                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                          };

                          for(var type in currencyTypes)
                          {
                          console.log("Currency: " + type);

                          console.log("Value: " + currencyTypes[type].value);
                          console.log("Name: " + currencyTypes[type].name);
                          console.log("Denomination: " + currencyTypes[type].denomination);

                          console.log("n");
                          }





                           var currencyTypes = {
                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                          };

                          for(var type in currencyTypes)
                          {
                          console.log("Currency: " + type);

                          console.log("Value: " + currencyTypes[type].value);
                          console.log("Name: " + currencyTypes[type].name);
                          console.log("Denomination: " + currencyTypes[type].denomination);

                          console.log("n");
                          }






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 16 '18 at 14:41









                          mbharanidharan88mbharanidharan88

                          4,11542455




                          4,11542455

























                              1

















                              const currencyTypes = {
                              NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                              EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                              USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                              GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                              };

                              function compileCurrenciesString(currencies) {
                              let outStr = '';
                              Object.keys(currencies).forEach((key) => {
                              outStr += currencyToString(key, currencies[key]);
                              outStr += 'n';
                              });
                              return outStr;
                              }

                              function currencyToString(key, currency) {
                              return `${key}, ${currency.name}, ${currency.value} ${currency.denomination}`;
                              }

                              console.log(compileCurrenciesString(currencyTypes));








                              share|improve this answer




























                                1

















                                const currencyTypes = {
                                NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                };

                                function compileCurrenciesString(currencies) {
                                let outStr = '';
                                Object.keys(currencies).forEach((key) => {
                                outStr += currencyToString(key, currencies[key]);
                                outStr += 'n';
                                });
                                return outStr;
                                }

                                function currencyToString(key, currency) {
                                return `${key}, ${currency.name}, ${currency.value} ${currency.denomination}`;
                                }

                                console.log(compileCurrenciesString(currencyTypes));








                                share|improve this answer


























                                  1












                                  1








                                  1










                                  const currencyTypes = {
                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                  };

                                  function compileCurrenciesString(currencies) {
                                  let outStr = '';
                                  Object.keys(currencies).forEach((key) => {
                                  outStr += currencyToString(key, currencies[key]);
                                  outStr += 'n';
                                  });
                                  return outStr;
                                  }

                                  function currencyToString(key, currency) {
                                  return `${key}, ${currency.name}, ${currency.value} ${currency.denomination}`;
                                  }

                                  console.log(compileCurrenciesString(currencyTypes));








                                  share|improve this answer
















                                  const currencyTypes = {
                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                  };

                                  function compileCurrenciesString(currencies) {
                                  let outStr = '';
                                  Object.keys(currencies).forEach((key) => {
                                  outStr += currencyToString(key, currencies[key]);
                                  outStr += 'n';
                                  });
                                  return outStr;
                                  }

                                  function currencyToString(key, currency) {
                                  return `${key}, ${currency.name}, ${currency.value} ${currency.denomination}`;
                                  }

                                  console.log(compileCurrenciesString(currencyTypes));








                                  const currencyTypes = {
                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                  };

                                  function compileCurrenciesString(currencies) {
                                  let outStr = '';
                                  Object.keys(currencies).forEach((key) => {
                                  outStr += currencyToString(key, currencies[key]);
                                  outStr += 'n';
                                  });
                                  return outStr;
                                  }

                                  function currencyToString(key, currency) {
                                  return `${key}, ${currency.name}, ${currency.value} ${currency.denomination}`;
                                  }

                                  console.log(compileCurrenciesString(currencyTypes));





                                  const currencyTypes = {
                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                  };

                                  function compileCurrenciesString(currencies) {
                                  let outStr = '';
                                  Object.keys(currencies).forEach((key) => {
                                  outStr += currencyToString(key, currencies[key]);
                                  outStr += 'n';
                                  });
                                  return outStr;
                                  }

                                  function currencyToString(key, currency) {
                                  return `${key}, ${currency.name}, ${currency.value} ${currency.denomination}`;
                                  }

                                  console.log(compileCurrenciesString(currencyTypes));






                                  share|improve this answer












                                  share|improve this answer



                                  share|improve this answer










                                  answered Nov 16 '18 at 14:47









                                  Daniil Andreyevich BaunovDaniil Andreyevich Baunov

                                  1,137528




                                  1,137528























                                      0














                                      You could use Object.keys(currencyTypes) to retrieve all of an objects keys, and then loop over those:






                                      const currencyTypes = {
                                      NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                      EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                      USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                      GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                      };

                                      Object.keys(currencyTypes).forEach(k => console.log(
                                      `${k}, ${currencyTypes[k].name}, ${currencyTypes[k].value} ${currencyTypes[k].denomination}`
                                      ));








                                      share|improve this answer




























                                        0














                                        You could use Object.keys(currencyTypes) to retrieve all of an objects keys, and then loop over those:






                                        const currencyTypes = {
                                        NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                        EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                        USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                        GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                        };

                                        Object.keys(currencyTypes).forEach(k => console.log(
                                        `${k}, ${currencyTypes[k].name}, ${currencyTypes[k].value} ${currencyTypes[k].denomination}`
                                        ));








                                        share|improve this answer


























                                          0












                                          0








                                          0







                                          You could use Object.keys(currencyTypes) to retrieve all of an objects keys, and then loop over those:






                                          const currencyTypes = {
                                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                          };

                                          Object.keys(currencyTypes).forEach(k => console.log(
                                          `${k}, ${currencyTypes[k].name}, ${currencyTypes[k].value} ${currencyTypes[k].denomination}`
                                          ));








                                          share|improve this answer













                                          You could use Object.keys(currencyTypes) to retrieve all of an objects keys, and then loop over those:






                                          const currencyTypes = {
                                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                          };

                                          Object.keys(currencyTypes).forEach(k => console.log(
                                          `${k}, ${currencyTypes[k].name}, ${currencyTypes[k].value} ${currencyTypes[k].denomination}`
                                          ));








                                          const currencyTypes = {
                                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                          };

                                          Object.keys(currencyTypes).forEach(k => console.log(
                                          `${k}, ${currencyTypes[k].name}, ${currencyTypes[k].value} ${currencyTypes[k].denomination}`
                                          ));





                                          const currencyTypes = {
                                          NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                          EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                          USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                          GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                          };

                                          Object.keys(currencyTypes).forEach(k => console.log(
                                          `${k}, ${currencyTypes[k].name}, ${currencyTypes[k].value} ${currencyTypes[k].denomination}`
                                          ));






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Nov 16 '18 at 14:44









                                          Olian04Olian04

                                          2,21011137




                                          2,21011137























                                              0














                                              You could use for...of loop with Object.entries to get key value.






                                              var currencyTypes = { NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" }, EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" }, USD: {value:0.12652, name: "United States dollar", denomination: "$" }, GBP: {value:0.09550, name: "Pound sterling", denomination: "£" }};

                                              for([key, {name, value, denomination}] of Object.entries(currencyTypes)) {
                                              let str = `${key}, ${name}, ${value} ${denomination}`
                                              console.log(str)
                                              }








                                              share|improve this answer




























                                                0














                                                You could use for...of loop with Object.entries to get key value.






                                                var currencyTypes = { NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" }, EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" }, USD: {value:0.12652, name: "United States dollar", denomination: "$" }, GBP: {value:0.09550, name: "Pound sterling", denomination: "£" }};

                                                for([key, {name, value, denomination}] of Object.entries(currencyTypes)) {
                                                let str = `${key}, ${name}, ${value} ${denomination}`
                                                console.log(str)
                                                }








                                                share|improve this answer


























                                                  0












                                                  0








                                                  0







                                                  You could use for...of loop with Object.entries to get key value.






                                                  var currencyTypes = { NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" }, EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" }, USD: {value:0.12652, name: "United States dollar", denomination: "$" }, GBP: {value:0.09550, name: "Pound sterling", denomination: "£" }};

                                                  for([key, {name, value, denomination}] of Object.entries(currencyTypes)) {
                                                  let str = `${key}, ${name}, ${value} ${denomination}`
                                                  console.log(str)
                                                  }








                                                  share|improve this answer













                                                  You could use for...of loop with Object.entries to get key value.






                                                  var currencyTypes = { NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" }, EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" }, USD: {value:0.12652, name: "United States dollar", denomination: "$" }, GBP: {value:0.09550, name: "Pound sterling", denomination: "£" }};

                                                  for([key, {name, value, denomination}] of Object.entries(currencyTypes)) {
                                                  let str = `${key}, ${name}, ${value} ${denomination}`
                                                  console.log(str)
                                                  }








                                                  var currencyTypes = { NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" }, EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" }, USD: {value:0.12652, name: "United States dollar", denomination: "$" }, GBP: {value:0.09550, name: "Pound sterling", denomination: "£" }};

                                                  for([key, {name, value, denomination}] of Object.entries(currencyTypes)) {
                                                  let str = `${key}, ${name}, ${value} ${denomination}`
                                                  console.log(str)
                                                  }





                                                  var currencyTypes = { NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" }, EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" }, USD: {value:0.12652, name: "United States dollar", denomination: "$" }, GBP: {value:0.09550, name: "Pound sterling", denomination: "£" }};

                                                  for([key, {name, value, denomination}] of Object.entries(currencyTypes)) {
                                                  let str = `${key}, ${name}, ${value} ${denomination}`
                                                  console.log(str)
                                                  }






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Nov 16 '18 at 14:45









                                                  Nenad VracarNenad Vracar

                                                  73.3k126085




                                                  73.3k126085























                                                      0














                                                      If you're coding to the ES6 spec then you can use destructuring assignment.



                                                      I also utilize Object.entries method to turn the object properties into an array of key value entry pairs - then iterate over that with Array.prototype.forEach.






                                                      var currencyTypes = {
                                                      NOK: {
                                                      value: 1.00000,
                                                      name: "Norske kroner",
                                                      denomination: "kr"
                                                      },
                                                      EUR: {
                                                      value: 0.10733,
                                                      name: "Europeiske euro",
                                                      denomination: "€"
                                                      },
                                                      USD: {
                                                      value: 0.12652,
                                                      name: "United States dollar",
                                                      denomination: "$"
                                                      },
                                                      GBP: {
                                                      value: 0.09550,
                                                      name: "Pound sterling",
                                                      denomination: "£"
                                                      },
                                                      };

                                                      Object.entries(currencyTypes).forEach(entry => {
                                                      const [key, val] = entry;
                                                      const {
                                                      value,
                                                      name,
                                                      denomination
                                                      } = val;
                                                      console.log(`${key}n${value}n${name}n${denomination}`);
                                                      });








                                                      share|improve this answer




























                                                        0














                                                        If you're coding to the ES6 spec then you can use destructuring assignment.



                                                        I also utilize Object.entries method to turn the object properties into an array of key value entry pairs - then iterate over that with Array.prototype.forEach.






                                                        var currencyTypes = {
                                                        NOK: {
                                                        value: 1.00000,
                                                        name: "Norske kroner",
                                                        denomination: "kr"
                                                        },
                                                        EUR: {
                                                        value: 0.10733,
                                                        name: "Europeiske euro",
                                                        denomination: "€"
                                                        },
                                                        USD: {
                                                        value: 0.12652,
                                                        name: "United States dollar",
                                                        denomination: "$"
                                                        },
                                                        GBP: {
                                                        value: 0.09550,
                                                        name: "Pound sterling",
                                                        denomination: "£"
                                                        },
                                                        };

                                                        Object.entries(currencyTypes).forEach(entry => {
                                                        const [key, val] = entry;
                                                        const {
                                                        value,
                                                        name,
                                                        denomination
                                                        } = val;
                                                        console.log(`${key}n${value}n${name}n${denomination}`);
                                                        });








                                                        share|improve this answer


























                                                          0












                                                          0








                                                          0







                                                          If you're coding to the ES6 spec then you can use destructuring assignment.



                                                          I also utilize Object.entries method to turn the object properties into an array of key value entry pairs - then iterate over that with Array.prototype.forEach.






                                                          var currencyTypes = {
                                                          NOK: {
                                                          value: 1.00000,
                                                          name: "Norske kroner",
                                                          denomination: "kr"
                                                          },
                                                          EUR: {
                                                          value: 0.10733,
                                                          name: "Europeiske euro",
                                                          denomination: "€"
                                                          },
                                                          USD: {
                                                          value: 0.12652,
                                                          name: "United States dollar",
                                                          denomination: "$"
                                                          },
                                                          GBP: {
                                                          value: 0.09550,
                                                          name: "Pound sterling",
                                                          denomination: "£"
                                                          },
                                                          };

                                                          Object.entries(currencyTypes).forEach(entry => {
                                                          const [key, val] = entry;
                                                          const {
                                                          value,
                                                          name,
                                                          denomination
                                                          } = val;
                                                          console.log(`${key}n${value}n${name}n${denomination}`);
                                                          });








                                                          share|improve this answer













                                                          If you're coding to the ES6 spec then you can use destructuring assignment.



                                                          I also utilize Object.entries method to turn the object properties into an array of key value entry pairs - then iterate over that with Array.prototype.forEach.






                                                          var currencyTypes = {
                                                          NOK: {
                                                          value: 1.00000,
                                                          name: "Norske kroner",
                                                          denomination: "kr"
                                                          },
                                                          EUR: {
                                                          value: 0.10733,
                                                          name: "Europeiske euro",
                                                          denomination: "€"
                                                          },
                                                          USD: {
                                                          value: 0.12652,
                                                          name: "United States dollar",
                                                          denomination: "$"
                                                          },
                                                          GBP: {
                                                          value: 0.09550,
                                                          name: "Pound sterling",
                                                          denomination: "£"
                                                          },
                                                          };

                                                          Object.entries(currencyTypes).forEach(entry => {
                                                          const [key, val] = entry;
                                                          const {
                                                          value,
                                                          name,
                                                          denomination
                                                          } = val;
                                                          console.log(`${key}n${value}n${name}n${denomination}`);
                                                          });








                                                          var currencyTypes = {
                                                          NOK: {
                                                          value: 1.00000,
                                                          name: "Norske kroner",
                                                          denomination: "kr"
                                                          },
                                                          EUR: {
                                                          value: 0.10733,
                                                          name: "Europeiske euro",
                                                          denomination: "€"
                                                          },
                                                          USD: {
                                                          value: 0.12652,
                                                          name: "United States dollar",
                                                          denomination: "$"
                                                          },
                                                          GBP: {
                                                          value: 0.09550,
                                                          name: "Pound sterling",
                                                          denomination: "£"
                                                          },
                                                          };

                                                          Object.entries(currencyTypes).forEach(entry => {
                                                          const [key, val] = entry;
                                                          const {
                                                          value,
                                                          name,
                                                          denomination
                                                          } = val;
                                                          console.log(`${key}n${value}n${name}n${denomination}`);
                                                          });





                                                          var currencyTypes = {
                                                          NOK: {
                                                          value: 1.00000,
                                                          name: "Norske kroner",
                                                          denomination: "kr"
                                                          },
                                                          EUR: {
                                                          value: 0.10733,
                                                          name: "Europeiske euro",
                                                          denomination: "€"
                                                          },
                                                          USD: {
                                                          value: 0.12652,
                                                          name: "United States dollar",
                                                          denomination: "$"
                                                          },
                                                          GBP: {
                                                          value: 0.09550,
                                                          name: "Pound sterling",
                                                          denomination: "£"
                                                          },
                                                          };

                                                          Object.entries(currencyTypes).forEach(entry => {
                                                          const [key, val] = entry;
                                                          const {
                                                          value,
                                                          name,
                                                          denomination
                                                          } = val;
                                                          console.log(`${key}n${value}n${name}n${denomination}`);
                                                          });






                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Nov 16 '18 at 14:56









                                                          Tom O.Tom O.

                                                          2,71121428




                                                          2,71121428























                                                              0














                                                              If you represent your collection as an array, it'll becomes easier to do this kind of things:






                                                              const currencyTypes = [
                                                              { "ticker": "NOK", "value":1.00000, "name": "Norske kroner", "denomination": "kr" },
                                                              { "ticker": "EUR", "value":0.10733, "name": "Europeiske euro", "denomination": "€" },
                                                              { "ticker": "USD", "value":0.12652, "name": "United States", "denomination": "$" },
                                                              { "ticker": "GBP", "value":0.09550, "name": "Pound sterling", "denomination": "£" }
                                                              ];
                                                              // Amount of currencies:
                                                              console.log( 'There are ' + currencyTypes.length + ' currencies in the array' );
                                                              // Array of all currency tickers:
                                                              console.log( currencyTypes.map( currency => currency.ticker ));
                                                              // Console.logging all of them:
                                                              currencyTypes.forEach( currency => console.log( currency ));
                                                              // Console.logging the properties using destructuring:
                                                              currencyTypes.forEach(({ ticker, value, name, denomination }) => console.log( ticker, value, name, denomination ));





                                                              When you have multiples of something, arrays are usually the easiest way since most objects representing collections can be created from the array in one line of code.



                                                              If you want to stay with using an object, look at Object.keys(), Object.values() and Object.entries(). Those will do alot of the converting back and forth from objects to arrays.



                                                              The function you coded to get the amount of keys in the object, basically is the same as Object.keys():






                                                              const currencyTypes = {
                                                              NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                                              EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                                              USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                                              GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                                              };

                                                              console.log( 'there are ' + Object.keys( currencyTypes ).length + ' currencies' );








                                                              share|improve this answer






























                                                                0














                                                                If you represent your collection as an array, it'll becomes easier to do this kind of things:






                                                                const currencyTypes = [
                                                                { "ticker": "NOK", "value":1.00000, "name": "Norske kroner", "denomination": "kr" },
                                                                { "ticker": "EUR", "value":0.10733, "name": "Europeiske euro", "denomination": "€" },
                                                                { "ticker": "USD", "value":0.12652, "name": "United States", "denomination": "$" },
                                                                { "ticker": "GBP", "value":0.09550, "name": "Pound sterling", "denomination": "£" }
                                                                ];
                                                                // Amount of currencies:
                                                                console.log( 'There are ' + currencyTypes.length + ' currencies in the array' );
                                                                // Array of all currency tickers:
                                                                console.log( currencyTypes.map( currency => currency.ticker ));
                                                                // Console.logging all of them:
                                                                currencyTypes.forEach( currency => console.log( currency ));
                                                                // Console.logging the properties using destructuring:
                                                                currencyTypes.forEach(({ ticker, value, name, denomination }) => console.log( ticker, value, name, denomination ));





                                                                When you have multiples of something, arrays are usually the easiest way since most objects representing collections can be created from the array in one line of code.



                                                                If you want to stay with using an object, look at Object.keys(), Object.values() and Object.entries(). Those will do alot of the converting back and forth from objects to arrays.



                                                                The function you coded to get the amount of keys in the object, basically is the same as Object.keys():






                                                                const currencyTypes = {
                                                                NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                                                EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                                                USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                                                GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                                                };

                                                                console.log( 'there are ' + Object.keys( currencyTypes ).length + ' currencies' );








                                                                share|improve this answer




























                                                                  0












                                                                  0








                                                                  0







                                                                  If you represent your collection as an array, it'll becomes easier to do this kind of things:






                                                                  const currencyTypes = [
                                                                  { "ticker": "NOK", "value":1.00000, "name": "Norske kroner", "denomination": "kr" },
                                                                  { "ticker": "EUR", "value":0.10733, "name": "Europeiske euro", "denomination": "€" },
                                                                  { "ticker": "USD", "value":0.12652, "name": "United States", "denomination": "$" },
                                                                  { "ticker": "GBP", "value":0.09550, "name": "Pound sterling", "denomination": "£" }
                                                                  ];
                                                                  // Amount of currencies:
                                                                  console.log( 'There are ' + currencyTypes.length + ' currencies in the array' );
                                                                  // Array of all currency tickers:
                                                                  console.log( currencyTypes.map( currency => currency.ticker ));
                                                                  // Console.logging all of them:
                                                                  currencyTypes.forEach( currency => console.log( currency ));
                                                                  // Console.logging the properties using destructuring:
                                                                  currencyTypes.forEach(({ ticker, value, name, denomination }) => console.log( ticker, value, name, denomination ));





                                                                  When you have multiples of something, arrays are usually the easiest way since most objects representing collections can be created from the array in one line of code.



                                                                  If you want to stay with using an object, look at Object.keys(), Object.values() and Object.entries(). Those will do alot of the converting back and forth from objects to arrays.



                                                                  The function you coded to get the amount of keys in the object, basically is the same as Object.keys():






                                                                  const currencyTypes = {
                                                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                                                  };

                                                                  console.log( 'there are ' + Object.keys( currencyTypes ).length + ' currencies' );








                                                                  share|improve this answer















                                                                  If you represent your collection as an array, it'll becomes easier to do this kind of things:






                                                                  const currencyTypes = [
                                                                  { "ticker": "NOK", "value":1.00000, "name": "Norske kroner", "denomination": "kr" },
                                                                  { "ticker": "EUR", "value":0.10733, "name": "Europeiske euro", "denomination": "€" },
                                                                  { "ticker": "USD", "value":0.12652, "name": "United States", "denomination": "$" },
                                                                  { "ticker": "GBP", "value":0.09550, "name": "Pound sterling", "denomination": "£" }
                                                                  ];
                                                                  // Amount of currencies:
                                                                  console.log( 'There are ' + currencyTypes.length + ' currencies in the array' );
                                                                  // Array of all currency tickers:
                                                                  console.log( currencyTypes.map( currency => currency.ticker ));
                                                                  // Console.logging all of them:
                                                                  currencyTypes.forEach( currency => console.log( currency ));
                                                                  // Console.logging the properties using destructuring:
                                                                  currencyTypes.forEach(({ ticker, value, name, denomination }) => console.log( ticker, value, name, denomination ));





                                                                  When you have multiples of something, arrays are usually the easiest way since most objects representing collections can be created from the array in one line of code.



                                                                  If you want to stay with using an object, look at Object.keys(), Object.values() and Object.entries(). Those will do alot of the converting back and forth from objects to arrays.



                                                                  The function you coded to get the amount of keys in the object, basically is the same as Object.keys():






                                                                  const currencyTypes = {
                                                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                                                  };

                                                                  console.log( 'there are ' + Object.keys( currencyTypes ).length + ' currencies' );








                                                                  const currencyTypes = [
                                                                  { "ticker": "NOK", "value":1.00000, "name": "Norske kroner", "denomination": "kr" },
                                                                  { "ticker": "EUR", "value":0.10733, "name": "Europeiske euro", "denomination": "€" },
                                                                  { "ticker": "USD", "value":0.12652, "name": "United States", "denomination": "$" },
                                                                  { "ticker": "GBP", "value":0.09550, "name": "Pound sterling", "denomination": "£" }
                                                                  ];
                                                                  // Amount of currencies:
                                                                  console.log( 'There are ' + currencyTypes.length + ' currencies in the array' );
                                                                  // Array of all currency tickers:
                                                                  console.log( currencyTypes.map( currency => currency.ticker ));
                                                                  // Console.logging all of them:
                                                                  currencyTypes.forEach( currency => console.log( currency ));
                                                                  // Console.logging the properties using destructuring:
                                                                  currencyTypes.forEach(({ ticker, value, name, denomination }) => console.log( ticker, value, name, denomination ));





                                                                  const currencyTypes = [
                                                                  { "ticker": "NOK", "value":1.00000, "name": "Norske kroner", "denomination": "kr" },
                                                                  { "ticker": "EUR", "value":0.10733, "name": "Europeiske euro", "denomination": "€" },
                                                                  { "ticker": "USD", "value":0.12652, "name": "United States", "denomination": "$" },
                                                                  { "ticker": "GBP", "value":0.09550, "name": "Pound sterling", "denomination": "£" }
                                                                  ];
                                                                  // Amount of currencies:
                                                                  console.log( 'There are ' + currencyTypes.length + ' currencies in the array' );
                                                                  // Array of all currency tickers:
                                                                  console.log( currencyTypes.map( currency => currency.ticker ));
                                                                  // Console.logging all of them:
                                                                  currencyTypes.forEach( currency => console.log( currency ));
                                                                  // Console.logging the properties using destructuring:
                                                                  currencyTypes.forEach(({ ticker, value, name, denomination }) => console.log( ticker, value, name, denomination ));





                                                                  const currencyTypes = {
                                                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                                                  };

                                                                  console.log( 'there are ' + Object.keys( currencyTypes ).length + ' currencies' );





                                                                  const currencyTypes = {
                                                                  NOK: {value:1.00000, name: "Norske kroner", denomination: "kr" },
                                                                  EUR: {value:0.10733, name: "Europeiske euro", denomination: "€" },
                                                                  USD: {value:0.12652, name: "United States dollar", denomination: "$" },
                                                                  GBP: {value:0.09550, name: "Pound sterling", denomination: "£" },
                                                                  };

                                                                  console.log( 'there are ' + Object.keys( currencyTypes ).length + ' currencies' );






                                                                  share|improve this answer














                                                                  share|improve this answer



                                                                  share|improve this answer








                                                                  edited Nov 16 '18 at 14:59

























                                                                  answered Nov 16 '18 at 14:52









                                                                  ShillyShilly

                                                                  5,9631717




                                                                  5,9631717






























                                                                      draft saved

                                                                      draft discarded




















































                                                                      Thanks for contributing an answer to Stack Overflow!


                                                                      • Please be sure to answer the question. Provide details and share your research!

                                                                      But avoid



                                                                      • Asking for help, clarification, or responding to other answers.

                                                                      • Making statements based on opinion; back them up with references or personal experience.


                                                                      To learn more, see our tips on writing great answers.




                                                                      draft saved


                                                                      draft discarded














                                                                      StackExchange.ready(
                                                                      function () {
                                                                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339924%2fhow-to-list-objects-including-value-name-denomination%23new-answer', 'question_page');
                                                                      }
                                                                      );

                                                                      Post as a guest















                                                                      Required, but never shown





















































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown

































                                                                      Required, but never shown














                                                                      Required, but never shown












                                                                      Required, but never shown







                                                                      Required, but never shown







                                                                      Popular posts from this blog

                                                                      Xamarin.iOS Cant Deploy on Iphone

                                                                      Glorious Revolution

                                                                      Dulmage-Mendelsohn matrix decomposition in Python