Convert an array of objects to array of the objects' values

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





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








33















I am trying to convert this array



let orders = [
amount: '100', user: 'admin', date: 'March 6, 2019' ,
amount: '120', user: 'admin', date: 'March 6, 2019' ,
amount: '80', user: 'admin', date: 'March 7, 2019' ,
amount: '200', user: 'admin', date: 'March 7, 2019' ,
];


to something like this



orders = [
['100', 'admin', 'March 6, 2019'],
['120', 'admin', 'March 6, 2019'],
['80', 'admin', 'March 7, 2019'],
['200', 'admin', 'March 7, 2019'],
];


and I have read that Objects.values() returns the values in an array, so I tried to iterate through the order array by using forEach() and using the Object.values on each item in the array.



let newOrders = orders.forEach(order => 
return Object.values(order);
);


I don't know if what I am doing is right and I am new to Javascript. Please help me.










share|improve this question



















  • 2





    Avoid forEach!

    – Bergi
    Mar 7 at 14:21






  • 5





    @Bergi why avoid forEach?

    – reggaeguitar
    Mar 7 at 17:13






  • 3





    @reggaeguitar It has too many limitations that you can trip you (like has happened here), I like for …of much better and recommend it universally for beginners

    – Bergi
    Mar 7 at 18:54


















33















I am trying to convert this array



let orders = [
amount: '100', user: 'admin', date: 'March 6, 2019' ,
amount: '120', user: 'admin', date: 'March 6, 2019' ,
amount: '80', user: 'admin', date: 'March 7, 2019' ,
amount: '200', user: 'admin', date: 'March 7, 2019' ,
];


to something like this



orders = [
['100', 'admin', 'March 6, 2019'],
['120', 'admin', 'March 6, 2019'],
['80', 'admin', 'March 7, 2019'],
['200', 'admin', 'March 7, 2019'],
];


and I have read that Objects.values() returns the values in an array, so I tried to iterate through the order array by using forEach() and using the Object.values on each item in the array.



let newOrders = orders.forEach(order => 
return Object.values(order);
);


I don't know if what I am doing is right and I am new to Javascript. Please help me.










share|improve this question



















  • 2





    Avoid forEach!

    – Bergi
    Mar 7 at 14:21






  • 5





    @Bergi why avoid forEach?

    – reggaeguitar
    Mar 7 at 17:13






  • 3





    @reggaeguitar It has too many limitations that you can trip you (like has happened here), I like for …of much better and recommend it universally for beginners

    – Bergi
    Mar 7 at 18:54














33












33








33


6






I am trying to convert this array



let orders = [
amount: '100', user: 'admin', date: 'March 6, 2019' ,
amount: '120', user: 'admin', date: 'March 6, 2019' ,
amount: '80', user: 'admin', date: 'March 7, 2019' ,
amount: '200', user: 'admin', date: 'March 7, 2019' ,
];


to something like this



orders = [
['100', 'admin', 'March 6, 2019'],
['120', 'admin', 'March 6, 2019'],
['80', 'admin', 'March 7, 2019'],
['200', 'admin', 'March 7, 2019'],
];


and I have read that Objects.values() returns the values in an array, so I tried to iterate through the order array by using forEach() and using the Object.values on each item in the array.



let newOrders = orders.forEach(order => 
return Object.values(order);
);


I don't know if what I am doing is right and I am new to Javascript. Please help me.










share|improve this question
















I am trying to convert this array



let orders = [
amount: '100', user: 'admin', date: 'March 6, 2019' ,
amount: '120', user: 'admin', date: 'March 6, 2019' ,
amount: '80', user: 'admin', date: 'March 7, 2019' ,
amount: '200', user: 'admin', date: 'March 7, 2019' ,
];


to something like this



orders = [
['100', 'admin', 'March 6, 2019'],
['120', 'admin', 'March 6, 2019'],
['80', 'admin', 'March 7, 2019'],
['200', 'admin', 'March 7, 2019'],
];


and I have read that Objects.values() returns the values in an array, so I tried to iterate through the order array by using forEach() and using the Object.values on each item in the array.



let newOrders = orders.forEach(order => 
return Object.values(order);
);


I don't know if what I am doing is right and I am new to Javascript. Please help me.







javascript arrays object javascript-objects






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 12:50









Mohammad Usman

21.5k134859




21.5k134859










asked Mar 7 at 10:44









sunny_adriannsunny_adriann

17817




17817







  • 2





    Avoid forEach!

    – Bergi
    Mar 7 at 14:21






  • 5





    @Bergi why avoid forEach?

    – reggaeguitar
    Mar 7 at 17:13






  • 3





    @reggaeguitar It has too many limitations that you can trip you (like has happened here), I like for …of much better and recommend it universally for beginners

    – Bergi
    Mar 7 at 18:54













  • 2





    Avoid forEach!

    – Bergi
    Mar 7 at 14:21






  • 5





    @Bergi why avoid forEach?

    – reggaeguitar
    Mar 7 at 17:13






  • 3





    @reggaeguitar It has too many limitations that you can trip you (like has happened here), I like for …of much better and recommend it universally for beginners

    – Bergi
    Mar 7 at 18:54








2




2





Avoid forEach!

– Bergi
Mar 7 at 14:21





Avoid forEach!

– Bergi
Mar 7 at 14:21




5




5





@Bergi why avoid forEach?

– reggaeguitar
Mar 7 at 17:13





@Bergi why avoid forEach?

– reggaeguitar
Mar 7 at 17:13




3




3





@reggaeguitar It has too many limitations that you can trip you (like has happened here), I like for …of much better and recommend it universally for beginners

– Bergi
Mar 7 at 18:54






@reggaeguitar It has too many limitations that you can trip you (like has happened here), I like for …of much better and recommend it universally for beginners

– Bergi
Mar 7 at 18:54













8 Answers
8






active

oldest

votes


















44














As order of values in array returned by Object.values() isn't guaranteed, you should consider use of .map() with some Object Destructuring. You can then extract object properties in separate variables and return them in desired order explicitly.






const data = [
amount: '100', user: 'admin', date: 'March 6, 2019' ,
amount: '120', user: 'admin', date: 'March 6, 2019' ,
amount: '80', user: 'admin', date: 'March 7, 2019' ,
amount: '200', user: 'admin', date: 'March 7, 2019'
];

const result = data.map(( amount, user, date ) => [amount, user, date]);

console.log(result);

.as-console-wrapper max-height: 100% !important; top: 0; 








share|improve this answer

























  • It doesn't seem to be mentioned in your Object destructuring link, but the order is preserved because variable names are relevant and should match the property names. const result = data.map(( date, amount, user ) => [amount, user, date]); works just as well even though the variable definitions has been modified. This link helped me understand.

    – Eric Duminil
    Mar 7 at 21:38


















22














The order in which the object's properties are enumerated is not guaranteed (ref). The simplest solution is to explicitly specify the keys in the desired order:



let result = orders.map(order => [order.amount, order.user, order.date]);





share|improve this answer
































    19














    Using destructuring. Use this if property ordering (of the object) is required in the output






    let orders = [
    amount: '100', user: 'admin', date: 'March 6, 2019' ,
    amount: '120', user: 'admin', date: 'March 6, 2019' ,
    amount: '80', user: 'admin', date: 'March 7, 2019' ,
    amount: '200', user: 'admin', date: 'March 7, 2019' ,
    ];

    console.log(orders.map((amount,user,date)=>[amount,user,date]))





    Use map and Object.values to get the values from the objects. This does not assure the order in the output will be the same as in the object Refer this






    let orders = [
    amount: '100', user: 'admin', date: 'March 6, 2019' ,
    amount: '120', user: 'admin', date: 'March 6, 2019' ,
    amount: '80', user: 'admin', date: 'March 7, 2019' ,
    amount: '200', user: 'admin', date: 'March 7, 2019' ,
    ];
    console.log(orders.map(e=>Object.values(e)))








    share|improve this answer




















    • 10





      Even simpler orders.map(Object.values)

      – kemicofa
      Mar 7 at 10:47






    • 13





      JS objects don't guarantee order

      – gronostaj
      Mar 7 at 12:13






    • 15





      It's relevant because it means your code could return ['100', 'admin', 'March 6, 2019'] for an order and ['admin', 80', 'March 7, 2019'] for another.

      – Eric Duminil
      Mar 7 at 14:09











    • The spec does not require the order, but apparently all major browsers follow the order anyway.

      – JollyJoker
      Mar 8 at 8:01











    • @JollyJoker False. I seem to remember that chrome has certain problems, especially when it comes to objects the have numerical keys. It orders it as 1, 111, 1245, 13 instead of 1, 13, 111, 1245.

      – I.Am.A.Guy
      Mar 8 at 8:23


















    3














    Simply use orders.map(Object.values)






    let orders = [
    amount: '100', user: 'admin', date: 'March 6, 2019' ,
    amount: '120', user: 'admin', date: 'March 6, 2019' ,
    amount: '80', user: 'admin', date: 'March 7, 2019' ,
    amount: '200', user: 'admin', date: 'March 7, 2019' ,
    ];

    const result = orders.map(Object.values);

    console.log(result)








    share|improve this answer






























      1














      you can try this:



      orders.map((order) => Object.values(order));


      map will return you a new array, while forEach just do callback on each element of array






      share|improve this answer
































        1

















        let orders = [
        amount: '100', user: 'admin', date: 'March 6, 2019' ,
        amount: '120', user: 'admin', date: 'March 6, 2019' ,
        amount: '80', user: 'admin', date: 'March 7, 2019' ,
        amount: '200', user: 'admin', date: 'March 7, 2019' ,
        ];

        const result = orders.map(Object.values);

        console.log(result)








        share|improve this answer






























          0














          A more robust solution, useful if you have many instances where you have these struct-like objects with different orders/keys. A functional approach, propsToArray takes a series of keys as individual parameters and returns a function which performs the desired transformation on the objects.






          let orders = [
          amount: '100', user: 'admin', date: 'March 6, 2019' ,
          amount: '120', user: 'admin', date: 'March 6, 2019' ,
          amount: '80', user: 'admin', date: 'March 7, 2019' ,
          amount: '200', user: 'admin', date: 'March 7, 2019' ,
          ];

          // option 1
          let propsToArray = function(...keys)
          return function(obj)
          return keys.map(key => obj[key]);

          ;
          // option 2
          // propsToArray = (...keys) => (obj) => keys.map(key => obj[key]);

          // resulting function
          let orderToArray = propsToArray("amount", "user", "date");

          console.log(orders.map(orderToArray));








          share|improve this answer






























            0

















            let orders = [
            amount: '100',
            user: 'admin',
            date: 'March 6, 2019'
            ,

            amount: '120',
            user: 'admin',
            date: 'March 6, 2019'
            ,

            amount: '80',
            user: 'admin',
            date: 'March 7, 2019'
            ,

            amount: '200',
            user: 'admin',
            date: 'March 7, 2019'
            ,
            ];

            let array = ; //initializing array
            orders.forEach((element) => //using array function for call back
            for (var j in element) //looping through each element of array
            array.push(element[j]); //pushing each value of object present inside the orders

            );
            console.log(array); //array is ready








            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%2f55041867%2fconvert-an-array-of-objects-to-array-of-the-objects-values%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              8 Answers
              8






              active

              oldest

              votes








              8 Answers
              8






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              44














              As order of values in array returned by Object.values() isn't guaranteed, you should consider use of .map() with some Object Destructuring. You can then extract object properties in separate variables and return them in desired order explicitly.






              const data = [
              amount: '100', user: 'admin', date: 'March 6, 2019' ,
              amount: '120', user: 'admin', date: 'March 6, 2019' ,
              amount: '80', user: 'admin', date: 'March 7, 2019' ,
              amount: '200', user: 'admin', date: 'March 7, 2019'
              ];

              const result = data.map(( amount, user, date ) => [amount, user, date]);

              console.log(result);

              .as-console-wrapper max-height: 100% !important; top: 0; 








              share|improve this answer

























              • It doesn't seem to be mentioned in your Object destructuring link, but the order is preserved because variable names are relevant and should match the property names. const result = data.map(( date, amount, user ) => [amount, user, date]); works just as well even though the variable definitions has been modified. This link helped me understand.

                – Eric Duminil
                Mar 7 at 21:38















              44














              As order of values in array returned by Object.values() isn't guaranteed, you should consider use of .map() with some Object Destructuring. You can then extract object properties in separate variables and return them in desired order explicitly.






              const data = [
              amount: '100', user: 'admin', date: 'March 6, 2019' ,
              amount: '120', user: 'admin', date: 'March 6, 2019' ,
              amount: '80', user: 'admin', date: 'March 7, 2019' ,
              amount: '200', user: 'admin', date: 'March 7, 2019'
              ];

              const result = data.map(( amount, user, date ) => [amount, user, date]);

              console.log(result);

              .as-console-wrapper max-height: 100% !important; top: 0; 








              share|improve this answer

























              • It doesn't seem to be mentioned in your Object destructuring link, but the order is preserved because variable names are relevant and should match the property names. const result = data.map(( date, amount, user ) => [amount, user, date]); works just as well even though the variable definitions has been modified. This link helped me understand.

                – Eric Duminil
                Mar 7 at 21:38













              44












              44








              44







              As order of values in array returned by Object.values() isn't guaranteed, you should consider use of .map() with some Object Destructuring. You can then extract object properties in separate variables and return them in desired order explicitly.






              const data = [
              amount: '100', user: 'admin', date: 'March 6, 2019' ,
              amount: '120', user: 'admin', date: 'March 6, 2019' ,
              amount: '80', user: 'admin', date: 'March 7, 2019' ,
              amount: '200', user: 'admin', date: 'March 7, 2019'
              ];

              const result = data.map(( amount, user, date ) => [amount, user, date]);

              console.log(result);

              .as-console-wrapper max-height: 100% !important; top: 0; 








              share|improve this answer















              As order of values in array returned by Object.values() isn't guaranteed, you should consider use of .map() with some Object Destructuring. You can then extract object properties in separate variables and return them in desired order explicitly.






              const data = [
              amount: '100', user: 'admin', date: 'March 6, 2019' ,
              amount: '120', user: 'admin', date: 'March 6, 2019' ,
              amount: '80', user: 'admin', date: 'March 7, 2019' ,
              amount: '200', user: 'admin', date: 'March 7, 2019'
              ];

              const result = data.map(( amount, user, date ) => [amount, user, date]);

              console.log(result);

              .as-console-wrapper max-height: 100% !important; top: 0; 








              const data = [
              amount: '100', user: 'admin', date: 'March 6, 2019' ,
              amount: '120', user: 'admin', date: 'March 6, 2019' ,
              amount: '80', user: 'admin', date: 'March 7, 2019' ,
              amount: '200', user: 'admin', date: 'March 7, 2019'
              ];

              const result = data.map(( amount, user, date ) => [amount, user, date]);

              console.log(result);

              .as-console-wrapper max-height: 100% !important; top: 0; 





              const data = [
              amount: '100', user: 'admin', date: 'March 6, 2019' ,
              amount: '120', user: 'admin', date: 'March 6, 2019' ,
              amount: '80', user: 'admin', date: 'March 7, 2019' ,
              amount: '200', user: 'admin', date: 'March 7, 2019'
              ];

              const result = data.map(( amount, user, date ) => [amount, user, date]);

              console.log(result);

              .as-console-wrapper max-height: 100% !important; top: 0; 






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 8 at 5:55

























              answered Mar 7 at 10:47









              Mohammad UsmanMohammad Usman

              21.5k134859




              21.5k134859












              • It doesn't seem to be mentioned in your Object destructuring link, but the order is preserved because variable names are relevant and should match the property names. const result = data.map(( date, amount, user ) => [amount, user, date]); works just as well even though the variable definitions has been modified. This link helped me understand.

                – Eric Duminil
                Mar 7 at 21:38

















              • It doesn't seem to be mentioned in your Object destructuring link, but the order is preserved because variable names are relevant and should match the property names. const result = data.map(( date, amount, user ) => [amount, user, date]); works just as well even though the variable definitions has been modified. This link helped me understand.

                – Eric Duminil
                Mar 7 at 21:38
















              It doesn't seem to be mentioned in your Object destructuring link, but the order is preserved because variable names are relevant and should match the property names. const result = data.map(( date, amount, user ) => [amount, user, date]); works just as well even though the variable definitions has been modified. This link helped me understand.

              – Eric Duminil
              Mar 7 at 21:38





              It doesn't seem to be mentioned in your Object destructuring link, but the order is preserved because variable names are relevant and should match the property names. const result = data.map(( date, amount, user ) => [amount, user, date]); works just as well even though the variable definitions has been modified. This link helped me understand.

              – Eric Duminil
              Mar 7 at 21:38













              22














              The order in which the object's properties are enumerated is not guaranteed (ref). The simplest solution is to explicitly specify the keys in the desired order:



              let result = orders.map(order => [order.amount, order.user, order.date]);





              share|improve this answer





























                22














                The order in which the object's properties are enumerated is not guaranteed (ref). The simplest solution is to explicitly specify the keys in the desired order:



                let result = orders.map(order => [order.amount, order.user, order.date]);





                share|improve this answer



























                  22












                  22








                  22







                  The order in which the object's properties are enumerated is not guaranteed (ref). The simplest solution is to explicitly specify the keys in the desired order:



                  let result = orders.map(order => [order.amount, order.user, order.date]);





                  share|improve this answer















                  The order in which the object's properties are enumerated is not guaranteed (ref). The simplest solution is to explicitly specify the keys in the desired order:



                  let result = orders.map(order => [order.amount, order.user, order.date]);






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 7 at 13:16

























                  answered Mar 7 at 12:36









                  Salman ASalman A

                  185k67346441




                  185k67346441





















                      19














                      Using destructuring. Use this if property ordering (of the object) is required in the output






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];

                      console.log(orders.map((amount,user,date)=>[amount,user,date]))





                      Use map and Object.values to get the values from the objects. This does not assure the order in the output will be the same as in the object Refer this






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];
                      console.log(orders.map(e=>Object.values(e)))








                      share|improve this answer




















                      • 10





                        Even simpler orders.map(Object.values)

                        – kemicofa
                        Mar 7 at 10:47






                      • 13





                        JS objects don't guarantee order

                        – gronostaj
                        Mar 7 at 12:13






                      • 15





                        It's relevant because it means your code could return ['100', 'admin', 'March 6, 2019'] for an order and ['admin', 80', 'March 7, 2019'] for another.

                        – Eric Duminil
                        Mar 7 at 14:09











                      • The spec does not require the order, but apparently all major browsers follow the order anyway.

                        – JollyJoker
                        Mar 8 at 8:01











                      • @JollyJoker False. I seem to remember that chrome has certain problems, especially when it comes to objects the have numerical keys. It orders it as 1, 111, 1245, 13 instead of 1, 13, 111, 1245.

                        – I.Am.A.Guy
                        Mar 8 at 8:23















                      19














                      Using destructuring. Use this if property ordering (of the object) is required in the output






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];

                      console.log(orders.map((amount,user,date)=>[amount,user,date]))





                      Use map and Object.values to get the values from the objects. This does not assure the order in the output will be the same as in the object Refer this






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];
                      console.log(orders.map(e=>Object.values(e)))








                      share|improve this answer




















                      • 10





                        Even simpler orders.map(Object.values)

                        – kemicofa
                        Mar 7 at 10:47






                      • 13





                        JS objects don't guarantee order

                        – gronostaj
                        Mar 7 at 12:13






                      • 15





                        It's relevant because it means your code could return ['100', 'admin', 'March 6, 2019'] for an order and ['admin', 80', 'March 7, 2019'] for another.

                        – Eric Duminil
                        Mar 7 at 14:09











                      • The spec does not require the order, but apparently all major browsers follow the order anyway.

                        – JollyJoker
                        Mar 8 at 8:01











                      • @JollyJoker False. I seem to remember that chrome has certain problems, especially when it comes to objects the have numerical keys. It orders it as 1, 111, 1245, 13 instead of 1, 13, 111, 1245.

                        – I.Am.A.Guy
                        Mar 8 at 8:23













                      19












                      19








                      19







                      Using destructuring. Use this if property ordering (of the object) is required in the output






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];

                      console.log(orders.map((amount,user,date)=>[amount,user,date]))





                      Use map and Object.values to get the values from the objects. This does not assure the order in the output will be the same as in the object Refer this






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];
                      console.log(orders.map(e=>Object.values(e)))








                      share|improve this answer















                      Using destructuring. Use this if property ordering (of the object) is required in the output






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];

                      console.log(orders.map((amount,user,date)=>[amount,user,date]))





                      Use map and Object.values to get the values from the objects. This does not assure the order in the output will be the same as in the object Refer this






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];
                      console.log(orders.map(e=>Object.values(e)))








                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];

                      console.log(orders.map((amount,user,date)=>[amount,user,date]))





                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];

                      console.log(orders.map((amount,user,date)=>[amount,user,date]))





                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];
                      console.log(orders.map(e=>Object.values(e)))





                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];
                      console.log(orders.map(e=>Object.values(e)))






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Mar 8 at 9:54

























                      answered Mar 7 at 10:45









                      ellipsisellipsis

                      8,3082929




                      8,3082929







                      • 10





                        Even simpler orders.map(Object.values)

                        – kemicofa
                        Mar 7 at 10:47






                      • 13





                        JS objects don't guarantee order

                        – gronostaj
                        Mar 7 at 12:13






                      • 15





                        It's relevant because it means your code could return ['100', 'admin', 'March 6, 2019'] for an order and ['admin', 80', 'March 7, 2019'] for another.

                        – Eric Duminil
                        Mar 7 at 14:09











                      • The spec does not require the order, but apparently all major browsers follow the order anyway.

                        – JollyJoker
                        Mar 8 at 8:01











                      • @JollyJoker False. I seem to remember that chrome has certain problems, especially when it comes to objects the have numerical keys. It orders it as 1, 111, 1245, 13 instead of 1, 13, 111, 1245.

                        – I.Am.A.Guy
                        Mar 8 at 8:23












                      • 10





                        Even simpler orders.map(Object.values)

                        – kemicofa
                        Mar 7 at 10:47






                      • 13





                        JS objects don't guarantee order

                        – gronostaj
                        Mar 7 at 12:13






                      • 15





                        It's relevant because it means your code could return ['100', 'admin', 'March 6, 2019'] for an order and ['admin', 80', 'March 7, 2019'] for another.

                        – Eric Duminil
                        Mar 7 at 14:09











                      • The spec does not require the order, but apparently all major browsers follow the order anyway.

                        – JollyJoker
                        Mar 8 at 8:01











                      • @JollyJoker False. I seem to remember that chrome has certain problems, especially when it comes to objects the have numerical keys. It orders it as 1, 111, 1245, 13 instead of 1, 13, 111, 1245.

                        – I.Am.A.Guy
                        Mar 8 at 8:23







                      10




                      10





                      Even simpler orders.map(Object.values)

                      – kemicofa
                      Mar 7 at 10:47





                      Even simpler orders.map(Object.values)

                      – kemicofa
                      Mar 7 at 10:47




                      13




                      13





                      JS objects don't guarantee order

                      – gronostaj
                      Mar 7 at 12:13





                      JS objects don't guarantee order

                      – gronostaj
                      Mar 7 at 12:13




                      15




                      15





                      It's relevant because it means your code could return ['100', 'admin', 'March 6, 2019'] for an order and ['admin', 80', 'March 7, 2019'] for another.

                      – Eric Duminil
                      Mar 7 at 14:09





                      It's relevant because it means your code could return ['100', 'admin', 'March 6, 2019'] for an order and ['admin', 80', 'March 7, 2019'] for another.

                      – Eric Duminil
                      Mar 7 at 14:09













                      The spec does not require the order, but apparently all major browsers follow the order anyway.

                      – JollyJoker
                      Mar 8 at 8:01





                      The spec does not require the order, but apparently all major browsers follow the order anyway.

                      – JollyJoker
                      Mar 8 at 8:01













                      @JollyJoker False. I seem to remember that chrome has certain problems, especially when it comes to objects the have numerical keys. It orders it as 1, 111, 1245, 13 instead of 1, 13, 111, 1245.

                      – I.Am.A.Guy
                      Mar 8 at 8:23





                      @JollyJoker False. I seem to remember that chrome has certain problems, especially when it comes to objects the have numerical keys. It orders it as 1, 111, 1245, 13 instead of 1, 13, 111, 1245.

                      – I.Am.A.Guy
                      Mar 8 at 8:23











                      3














                      Simply use orders.map(Object.values)






                      let orders = [
                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                      ];

                      const result = orders.map(Object.values);

                      console.log(result)








                      share|improve this answer



























                        3














                        Simply use orders.map(Object.values)






                        let orders = [
                        amount: '100', user: 'admin', date: 'March 6, 2019' ,
                        amount: '120', user: 'admin', date: 'March 6, 2019' ,
                        amount: '80', user: 'admin', date: 'March 7, 2019' ,
                        amount: '200', user: 'admin', date: 'March 7, 2019' ,
                        ];

                        const result = orders.map(Object.values);

                        console.log(result)








                        share|improve this answer

























                          3












                          3








                          3







                          Simply use orders.map(Object.values)






                          let orders = [
                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                          ];

                          const result = orders.map(Object.values);

                          console.log(result)








                          share|improve this answer













                          Simply use orders.map(Object.values)






                          let orders = [
                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                          ];

                          const result = orders.map(Object.values);

                          console.log(result)








                          let orders = [
                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                          ];

                          const result = orders.map(Object.values);

                          console.log(result)





                          let orders = [
                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                          ];

                          const result = orders.map(Object.values);

                          console.log(result)






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 7 at 11:11









                          Khyati SharmaKhyati Sharma

                          837




                          837





















                              1














                              you can try this:



                              orders.map((order) => Object.values(order));


                              map will return you a new array, while forEach just do callback on each element of array






                              share|improve this answer





























                                1














                                you can try this:



                                orders.map((order) => Object.values(order));


                                map will return you a new array, while forEach just do callback on each element of array






                                share|improve this answer



























                                  1












                                  1








                                  1







                                  you can try this:



                                  orders.map((order) => Object.values(order));


                                  map will return you a new array, while forEach just do callback on each element of array






                                  share|improve this answer















                                  you can try this:



                                  orders.map((order) => Object.values(order));


                                  map will return you a new array, while forEach just do callback on each element of array







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Mar 8 at 10:11

























                                  answered Mar 7 at 10:52









                                  Mateusz JabłońskiMateusz Jabłoński

                                  212




                                  212





















                                      1

















                                      let orders = [
                                      amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                      amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                      amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                      amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                      ];

                                      const result = orders.map(Object.values);

                                      console.log(result)








                                      share|improve this answer



























                                        1

















                                        let orders = [
                                        amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                        amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                        amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                        amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                        ];

                                        const result = orders.map(Object.values);

                                        console.log(result)








                                        share|improve this answer

























                                          1












                                          1








                                          1










                                          let orders = [
                                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                          ];

                                          const result = orders.map(Object.values);

                                          console.log(result)








                                          share|improve this answer
















                                          let orders = [
                                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                          ];

                                          const result = orders.map(Object.values);

                                          console.log(result)








                                          let orders = [
                                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                          ];

                                          const result = orders.map(Object.values);

                                          console.log(result)





                                          let orders = [
                                          amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                          amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                          amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                          ];

                                          const result = orders.map(Object.values);

                                          console.log(result)






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Mar 13 at 11:58









                                          VipulVipul

                                          111




                                          111





















                                              0














                                              A more robust solution, useful if you have many instances where you have these struct-like objects with different orders/keys. A functional approach, propsToArray takes a series of keys as individual parameters and returns a function which performs the desired transformation on the objects.






                                              let orders = [
                                              amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                              amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                              amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                              amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                              ];

                                              // option 1
                                              let propsToArray = function(...keys)
                                              return function(obj)
                                              return keys.map(key => obj[key]);

                                              ;
                                              // option 2
                                              // propsToArray = (...keys) => (obj) => keys.map(key => obj[key]);

                                              // resulting function
                                              let orderToArray = propsToArray("amount", "user", "date");

                                              console.log(orders.map(orderToArray));








                                              share|improve this answer



























                                                0














                                                A more robust solution, useful if you have many instances where you have these struct-like objects with different orders/keys. A functional approach, propsToArray takes a series of keys as individual parameters and returns a function which performs the desired transformation on the objects.






                                                let orders = [
                                                amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                                amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                                amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                                amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                                ];

                                                // option 1
                                                let propsToArray = function(...keys)
                                                return function(obj)
                                                return keys.map(key => obj[key]);

                                                ;
                                                // option 2
                                                // propsToArray = (...keys) => (obj) => keys.map(key => obj[key]);

                                                // resulting function
                                                let orderToArray = propsToArray("amount", "user", "date");

                                                console.log(orders.map(orderToArray));








                                                share|improve this answer

























                                                  0












                                                  0








                                                  0







                                                  A more robust solution, useful if you have many instances where you have these struct-like objects with different orders/keys. A functional approach, propsToArray takes a series of keys as individual parameters and returns a function which performs the desired transformation on the objects.






                                                  let orders = [
                                                  amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                                  amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                                  ];

                                                  // option 1
                                                  let propsToArray = function(...keys)
                                                  return function(obj)
                                                  return keys.map(key => obj[key]);

                                                  ;
                                                  // option 2
                                                  // propsToArray = (...keys) => (obj) => keys.map(key => obj[key]);

                                                  // resulting function
                                                  let orderToArray = propsToArray("amount", "user", "date");

                                                  console.log(orders.map(orderToArray));








                                                  share|improve this answer













                                                  A more robust solution, useful if you have many instances where you have these struct-like objects with different orders/keys. A functional approach, propsToArray takes a series of keys as individual parameters and returns a function which performs the desired transformation on the objects.






                                                  let orders = [
                                                  amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                                  amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                                  ];

                                                  // option 1
                                                  let propsToArray = function(...keys)
                                                  return function(obj)
                                                  return keys.map(key => obj[key]);

                                                  ;
                                                  // option 2
                                                  // propsToArray = (...keys) => (obj) => keys.map(key => obj[key]);

                                                  // resulting function
                                                  let orderToArray = propsToArray("amount", "user", "date");

                                                  console.log(orders.map(orderToArray));








                                                  let orders = [
                                                  amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                                  amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                                  ];

                                                  // option 1
                                                  let propsToArray = function(...keys)
                                                  return function(obj)
                                                  return keys.map(key => obj[key]);

                                                  ;
                                                  // option 2
                                                  // propsToArray = (...keys) => (obj) => keys.map(key => obj[key]);

                                                  // resulting function
                                                  let orderToArray = propsToArray("amount", "user", "date");

                                                  console.log(orders.map(orderToArray));





                                                  let orders = [
                                                  amount: '100', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '120', user: 'admin', date: 'March 6, 2019' ,
                                                  amount: '80', user: 'admin', date: 'March 7, 2019' ,
                                                  amount: '200', user: 'admin', date: 'March 7, 2019' ,
                                                  ];

                                                  // option 1
                                                  let propsToArray = function(...keys)
                                                  return function(obj)
                                                  return keys.map(key => obj[key]);

                                                  ;
                                                  // option 2
                                                  // propsToArray = (...keys) => (obj) => keys.map(key => obj[key]);

                                                  // resulting function
                                                  let orderToArray = propsToArray("amount", "user", "date");

                                                  console.log(orders.map(orderToArray));






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Mar 7 at 18:47









                                                  Conor O'BrienConor O'Brien

                                                  51811329




                                                  51811329





















                                                      0

















                                                      let orders = [
                                                      amount: '100',
                                                      user: 'admin',
                                                      date: 'March 6, 2019'
                                                      ,

                                                      amount: '120',
                                                      user: 'admin',
                                                      date: 'March 6, 2019'
                                                      ,

                                                      amount: '80',
                                                      user: 'admin',
                                                      date: 'March 7, 2019'
                                                      ,

                                                      amount: '200',
                                                      user: 'admin',
                                                      date: 'March 7, 2019'
                                                      ,
                                                      ];

                                                      let array = ; //initializing array
                                                      orders.forEach((element) => //using array function for call back
                                                      for (var j in element) //looping through each element of array
                                                      array.push(element[j]); //pushing each value of object present inside the orders

                                                      );
                                                      console.log(array); //array is ready








                                                      share|improve this answer





























                                                        0

















                                                        let orders = [
                                                        amount: '100',
                                                        user: 'admin',
                                                        date: 'March 6, 2019'
                                                        ,

                                                        amount: '120',
                                                        user: 'admin',
                                                        date: 'March 6, 2019'
                                                        ,

                                                        amount: '80',
                                                        user: 'admin',
                                                        date: 'March 7, 2019'
                                                        ,

                                                        amount: '200',
                                                        user: 'admin',
                                                        date: 'March 7, 2019'
                                                        ,
                                                        ];

                                                        let array = ; //initializing array
                                                        orders.forEach((element) => //using array function for call back
                                                        for (var j in element) //looping through each element of array
                                                        array.push(element[j]); //pushing each value of object present inside the orders

                                                        );
                                                        console.log(array); //array is ready








                                                        share|improve this answer



























                                                          0












                                                          0








                                                          0










                                                          let orders = [
                                                          amount: '100',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '120',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '80',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,

                                                          amount: '200',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,
                                                          ];

                                                          let array = ; //initializing array
                                                          orders.forEach((element) => //using array function for call back
                                                          for (var j in element) //looping through each element of array
                                                          array.push(element[j]); //pushing each value of object present inside the orders

                                                          );
                                                          console.log(array); //array is ready








                                                          share|improve this answer


















                                                          let orders = [
                                                          amount: '100',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '120',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '80',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,

                                                          amount: '200',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,
                                                          ];

                                                          let array = ; //initializing array
                                                          orders.forEach((element) => //using array function for call back
                                                          for (var j in element) //looping through each element of array
                                                          array.push(element[j]); //pushing each value of object present inside the orders

                                                          );
                                                          console.log(array); //array is ready








                                                          let orders = [
                                                          amount: '100',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '120',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '80',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,

                                                          amount: '200',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,
                                                          ];

                                                          let array = ; //initializing array
                                                          orders.forEach((element) => //using array function for call back
                                                          for (var j in element) //looping through each element of array
                                                          array.push(element[j]); //pushing each value of object present inside the orders

                                                          );
                                                          console.log(array); //array is ready





                                                          let orders = [
                                                          amount: '100',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '120',
                                                          user: 'admin',
                                                          date: 'March 6, 2019'
                                                          ,

                                                          amount: '80',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,

                                                          amount: '200',
                                                          user: 'admin',
                                                          date: 'March 7, 2019'
                                                          ,
                                                          ];

                                                          let array = ; //initializing array
                                                          orders.forEach((element) => //using array function for call back
                                                          for (var j in element) //looping through each element of array
                                                          array.push(element[j]); //pushing each value of object present inside the orders

                                                          );
                                                          console.log(array); //array is ready






                                                          share|improve this answer














                                                          share|improve this answer



                                                          share|improve this answer








                                                          edited Mar 22 at 15:57









                                                          demo

                                                          2,41444084




                                                          2,41444084










                                                          answered Mar 13 at 12:06









                                                          VipulVipul

                                                          111




                                                          111



























                                                              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%2f55041867%2fconvert-an-array-of-objects-to-array-of-the-objects-values%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

                                                              How to check contact read email or not when send email to Individual?

                                                              Bahrain

                                                              Postfix configuration issue with fips on centos 7; mailgun relay