How do I convert array of Objects into one Object in JavaScript?












31















I have an array of Objects:



[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]


How do I convert it into the following by JavaScript?



{"11":"1000", "22":"2200"}









share|improve this question

























  • what language you wanna use in order to convert it?

    – silicakes
    Nov 9 '13 at 9:47











  • @Mike86 I want to use JavaScript

    – Vijay Chouhan
    Nov 9 '13 at 9:48











  • Do you accept the above as a string?

    – silicakes
    Nov 9 '13 at 9:53











  • By the way, those are Objects

    – Alexander
    Nov 9 '13 at 9:55






  • 2





    [{key:"11", value:"1100"}, {key:"22", value:"2200"}].reduce(function(m,v){m[v.key] = v.value; return m;}, {})

    – david
    Nov 9 '13 at 9:57
















31















I have an array of Objects:



[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]


How do I convert it into the following by JavaScript?



{"11":"1000", "22":"2200"}









share|improve this question

























  • what language you wanna use in order to convert it?

    – silicakes
    Nov 9 '13 at 9:47











  • @Mike86 I want to use JavaScript

    – Vijay Chouhan
    Nov 9 '13 at 9:48











  • Do you accept the above as a string?

    – silicakes
    Nov 9 '13 at 9:53











  • By the way, those are Objects

    – Alexander
    Nov 9 '13 at 9:55






  • 2





    [{key:"11", value:"1100"}, {key:"22", value:"2200"}].reduce(function(m,v){m[v.key] = v.value; return m;}, {})

    – david
    Nov 9 '13 at 9:57














31












31








31


8






I have an array of Objects:



[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]


How do I convert it into the following by JavaScript?



{"11":"1000", "22":"2200"}









share|improve this question
















I have an array of Objects:



[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]


How do I convert it into the following by JavaScript?



{"11":"1000", "22":"2200"}






javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 13 '18 at 3:38









Pang

6,9011664101




6,9011664101










asked Nov 9 '13 at 9:44









Vijay ChouhanVijay Chouhan

1,86331932




1,86331932













  • what language you wanna use in order to convert it?

    – silicakes
    Nov 9 '13 at 9:47











  • @Mike86 I want to use JavaScript

    – Vijay Chouhan
    Nov 9 '13 at 9:48











  • Do you accept the above as a string?

    – silicakes
    Nov 9 '13 at 9:53











  • By the way, those are Objects

    – Alexander
    Nov 9 '13 at 9:55






  • 2





    [{key:"11", value:"1100"}, {key:"22", value:"2200"}].reduce(function(m,v){m[v.key] = v.value; return m;}, {})

    – david
    Nov 9 '13 at 9:57



















  • what language you wanna use in order to convert it?

    – silicakes
    Nov 9 '13 at 9:47











  • @Mike86 I want to use JavaScript

    – Vijay Chouhan
    Nov 9 '13 at 9:48











  • Do you accept the above as a string?

    – silicakes
    Nov 9 '13 at 9:53











  • By the way, those are Objects

    – Alexander
    Nov 9 '13 at 9:55






  • 2





    [{key:"11", value:"1100"}, {key:"22", value:"2200"}].reduce(function(m,v){m[v.key] = v.value; return m;}, {})

    – david
    Nov 9 '13 at 9:57

















what language you wanna use in order to convert it?

– silicakes
Nov 9 '13 at 9:47





what language you wanna use in order to convert it?

– silicakes
Nov 9 '13 at 9:47













@Mike86 I want to use JavaScript

– Vijay Chouhan
Nov 9 '13 at 9:48





@Mike86 I want to use JavaScript

– Vijay Chouhan
Nov 9 '13 at 9:48













Do you accept the above as a string?

– silicakes
Nov 9 '13 at 9:53





Do you accept the above as a string?

– silicakes
Nov 9 '13 at 9:53













By the way, those are Objects

– Alexander
Nov 9 '13 at 9:55





By the way, those are Objects

– Alexander
Nov 9 '13 at 9:55




2




2





[{key:"11", value:"1100"}, {key:"22", value:"2200"}].reduce(function(m,v){m[v.key] = v.value; return m;}, {})

– david
Nov 9 '13 at 9:57





[{key:"11", value:"1100"}, {key:"22", value:"2200"}].reduce(function(m,v){m[v.key] = v.value; return m;}, {})

– david
Nov 9 '13 at 9:57












11 Answers
11






active

oldest

votes


















21














You're probably looking for something like this:



// original
var arr = [
{key : '11', value : '1100', $$hashKey : '00X' },
{key : '22', value : '2200', $$hashKey : '018' }
];

//convert
var result = {};
for (var i=0; i<arr.length; i++) {
result[arr[i].key] = arr[i].value;
}

//result
console.log(result);





share|improve this answer































    40














    I like the functional approach to achieve this task:



    var arr = [{ key:"11", value:"1100" }, { key:"22", value:"2200" }];
    var result = arr.reduce(function(obj,item){
    obj[item.key] = item.value;
    return obj;
    }, {});


    Note: Last {} is the initial obj value for reduce function, if you won't provide the initial value the first arr element will be used (which is probably undesirable).



    https://jsfiddle.net/GreQ/2xa078da/






    share|improve this answer





















    • 1





      and if the key is dynamic?

      – Stefano Saitta
      Jun 2 '16 at 10:45






    • 1





      Well, you should know which property of the given item/object should be used as key and which as value no? But if we assume that wfirst prop is always the key and second the value we could use a callback function like this: function(obj,item){ var keys = item.keys(); obj[item[keys[0]]] = item[keys[0]]; return obj; }

      – GreQ
      Jun 24 '16 at 7:33













    • Correction of callback above: code var obj = arr.reduce(function(obj,item){ var keys = Object.keys(item); obj[item[keys[0]]] = item[keys[1]]; return obj; },{});

      – GreQ
      Jun 24 '16 at 7:48



















    33














    Tiny ES6 solution can look like:



    var arr = [{key:"11", value:"1100"},{key:"22", value:"2200"}];
    var object = arr.reduce(
    (obj, item) => Object.assign(obj, {[item.key]: item.value}) ,{});


    Also, if you use object spread, than it can look like:



    var object = arr.reduce((obj, item) => ({...obj, {[item.key]: item.value}}) ,{});


    One more solution that is 99% faster is(tested on jsperf):



    var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});


    Here we benefit from comma operator, it evaluates all expression before comma and returns a last one(after last comma). So we don't copy obj each time, rather assigning new property to it.






    share|improve this answer





















    • 1





      The simplest answer of all, yet the most elegant too

      – Jeremy Belolo
      Nov 9 '17 at 18:49













    • Loved the one! var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});

      – Sohail
      Aug 21 '18 at 13:36



















    7














    Trying to fix this answer, this should do it:






    var array = [
    {key:'k1',value:'v1'},
    {key:'k2',value:'v2'},
    {key:'k3',value:'v3'}
    ];
    var mapped = array .map(item => ({ [item.key]: item.value }) );
    var newObj = Object.assign({}, ...mapped );
    console.log(newObj );








    One-liner:

    var newObj = Object.assign({}, ...(array.map(item => ({ [item.key]: item.value }) )));





    share|improve this answer

































      5














      A clean way to do this using modern JavaScript is as follows:



      const array = [
      { name: "something", value: "something" },
      { name: "somethingElse", value: "something else" },
      ];

      const newObject = Object.assign({}, ...array.map(item => ({ [item.name]: item.value })));

      // >> { something: "something", somethingElse: "something else" }





      share|improve this answer































        4














        Use lodash!



        const obj = _.keyBy(arrayOfObjects, 'keyName')





        share|improve this answer































          2














          Using Underscore.js:



          var myArray = [
          Object { key="11", value="1100", $$hashKey="00X"},
          Object { key="22", value="2200", $$hashKey="018"}
          ];
          var myObj = _.object(_.pluck(myArray, 'key'), _.pluck(myArray, 'value'));





          share|improve this answer































            0














            Here you go:



            var arr = [{ key: "11", value: "1100" }, { key: "22", value: "2200" }];
            var result = {};
            for (var i=0, len=arr.length; i < len; i++) {
            result[arr[i].key] = arr[i].value;
            }
            console.log(result); // {11: "1000", 22: "2200"}





            share|improve this answer
























            • This surprisingly resembles the answer someone posted like 5 minutes ago

              – Alexander
              Nov 9 '13 at 10:04






            • 1





              Because that's how you solve this problem. About the naming for example: array is a reserved keyword so people use arr instead. etc.

              – pstadler
              Nov 9 '13 at 10:36





















            0














            Here's how to dynamically accept the above as a string and interpolate it into an object:



            var stringObject = '[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]';

            function interpolateStringObject(stringObject) {
            var jsObj = {};
            var processedObj = stringObject.split("[Object { ");
            processedObj = processedObj[1].split("},");
            $.each(processedObj, function (i, v) {
            jsObj[v.split("key=")[1].split(",")[0]] = v.split("value=")[1].split(",")[0].replace(/"/g,'');
            });

            return jsObj
            }

            var t = interpolateStringObject(stringObject); //t is the object you want


            http://jsfiddle.net/3QKmX/1/






            share|improve this answer































              0

















              // original
              var arr = [{
              key: '11',
              value: '1100',
              $$hashKey: '00X'
              },
              {
              key: '22',
              value: '2200',
              $$hashKey: '018'
              }
              ];

              // My solution
              var obj = {};
              for (let i = 0; i < arr.length; i++) {
              obj[arr[i].key] = arr[i].value;
              }
              console.log(obj)








              share|improve this answer


























              • While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.

                – Roshana Pitigala
                Jul 4 '18 at 18:23



















              -1














                      var obj = [
              {id: 1 , name : 'gaju' , class : 'kv'},
              {id: 2 , name : 'tushar' , class : 'Super'}
              ];

              function conv(obj,arg){
              var temp= {};
              var output= {}
              for(key in obj){
              temp[key] = obj[key];
              };

              var i=0;
              for(key in temp){
              var aa = {};
              var value = temp[key][arg];
              aa[value] = temp[i];
              //console.log(aa[value][arg] );
              output[aa[value][arg]]= aa[value];
              i++;
              }

              console.log(output);
              }

              calling function

              conv(obj,'class');





              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%2f19874555%2fhow-do-i-convert-array-of-objects-into-one-object-in-javascript%23new-answer', 'question_page');
                }
                );

                Post as a guest















                Required, but never shown

























                11 Answers
                11






                active

                oldest

                votes








                11 Answers
                11






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                21














                You're probably looking for something like this:



                // original
                var arr = [
                {key : '11', value : '1100', $$hashKey : '00X' },
                {key : '22', value : '2200', $$hashKey : '018' }
                ];

                //convert
                var result = {};
                for (var i=0; i<arr.length; i++) {
                result[arr[i].key] = arr[i].value;
                }

                //result
                console.log(result);





                share|improve this answer




























                  21














                  You're probably looking for something like this:



                  // original
                  var arr = [
                  {key : '11', value : '1100', $$hashKey : '00X' },
                  {key : '22', value : '2200', $$hashKey : '018' }
                  ];

                  //convert
                  var result = {};
                  for (var i=0; i<arr.length; i++) {
                  result[arr[i].key] = arr[i].value;
                  }

                  //result
                  console.log(result);





                  share|improve this answer


























                    21












                    21








                    21







                    You're probably looking for something like this:



                    // original
                    var arr = [
                    {key : '11', value : '1100', $$hashKey : '00X' },
                    {key : '22', value : '2200', $$hashKey : '018' }
                    ];

                    //convert
                    var result = {};
                    for (var i=0; i<arr.length; i++) {
                    result[arr[i].key] = arr[i].value;
                    }

                    //result
                    console.log(result);





                    share|improve this answer













                    You're probably looking for something like this:



                    // original
                    var arr = [
                    {key : '11', value : '1100', $$hashKey : '00X' },
                    {key : '22', value : '2200', $$hashKey : '018' }
                    ];

                    //convert
                    var result = {};
                    for (var i=0; i<arr.length; i++) {
                    result[arr[i].key] = arr[i].value;
                    }

                    //result
                    console.log(result);






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 9 '13 at 9:55









                    TibosTibos

                    23.3k23456




                    23.3k23456

























                        40














                        I like the functional approach to achieve this task:



                        var arr = [{ key:"11", value:"1100" }, { key:"22", value:"2200" }];
                        var result = arr.reduce(function(obj,item){
                        obj[item.key] = item.value;
                        return obj;
                        }, {});


                        Note: Last {} is the initial obj value for reduce function, if you won't provide the initial value the first arr element will be used (which is probably undesirable).



                        https://jsfiddle.net/GreQ/2xa078da/






                        share|improve this answer





















                        • 1





                          and if the key is dynamic?

                          – Stefano Saitta
                          Jun 2 '16 at 10:45






                        • 1





                          Well, you should know which property of the given item/object should be used as key and which as value no? But if we assume that wfirst prop is always the key and second the value we could use a callback function like this: function(obj,item){ var keys = item.keys(); obj[item[keys[0]]] = item[keys[0]]; return obj; }

                          – GreQ
                          Jun 24 '16 at 7:33













                        • Correction of callback above: code var obj = arr.reduce(function(obj,item){ var keys = Object.keys(item); obj[item[keys[0]]] = item[keys[1]]; return obj; },{});

                          – GreQ
                          Jun 24 '16 at 7:48
















                        40














                        I like the functional approach to achieve this task:



                        var arr = [{ key:"11", value:"1100" }, { key:"22", value:"2200" }];
                        var result = arr.reduce(function(obj,item){
                        obj[item.key] = item.value;
                        return obj;
                        }, {});


                        Note: Last {} is the initial obj value for reduce function, if you won't provide the initial value the first arr element will be used (which is probably undesirable).



                        https://jsfiddle.net/GreQ/2xa078da/






                        share|improve this answer





















                        • 1





                          and if the key is dynamic?

                          – Stefano Saitta
                          Jun 2 '16 at 10:45






                        • 1





                          Well, you should know which property of the given item/object should be used as key and which as value no? But if we assume that wfirst prop is always the key and second the value we could use a callback function like this: function(obj,item){ var keys = item.keys(); obj[item[keys[0]]] = item[keys[0]]; return obj; }

                          – GreQ
                          Jun 24 '16 at 7:33













                        • Correction of callback above: code var obj = arr.reduce(function(obj,item){ var keys = Object.keys(item); obj[item[keys[0]]] = item[keys[1]]; return obj; },{});

                          – GreQ
                          Jun 24 '16 at 7:48














                        40












                        40








                        40







                        I like the functional approach to achieve this task:



                        var arr = [{ key:"11", value:"1100" }, { key:"22", value:"2200" }];
                        var result = arr.reduce(function(obj,item){
                        obj[item.key] = item.value;
                        return obj;
                        }, {});


                        Note: Last {} is the initial obj value for reduce function, if you won't provide the initial value the first arr element will be used (which is probably undesirable).



                        https://jsfiddle.net/GreQ/2xa078da/






                        share|improve this answer















                        I like the functional approach to achieve this task:



                        var arr = [{ key:"11", value:"1100" }, { key:"22", value:"2200" }];
                        var result = arr.reduce(function(obj,item){
                        obj[item.key] = item.value;
                        return obj;
                        }, {});


                        Note: Last {} is the initial obj value for reduce function, if you won't provide the initial value the first arr element will be used (which is probably undesirable).



                        https://jsfiddle.net/GreQ/2xa078da/







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jun 29 '17 at 12:40









                        jmarceli

                        10.9k43943




                        10.9k43943










                        answered May 13 '16 at 17:10









                        GreQGreQ

                        561165




                        561165








                        • 1





                          and if the key is dynamic?

                          – Stefano Saitta
                          Jun 2 '16 at 10:45






                        • 1





                          Well, you should know which property of the given item/object should be used as key and which as value no? But if we assume that wfirst prop is always the key and second the value we could use a callback function like this: function(obj,item){ var keys = item.keys(); obj[item[keys[0]]] = item[keys[0]]; return obj; }

                          – GreQ
                          Jun 24 '16 at 7:33













                        • Correction of callback above: code var obj = arr.reduce(function(obj,item){ var keys = Object.keys(item); obj[item[keys[0]]] = item[keys[1]]; return obj; },{});

                          – GreQ
                          Jun 24 '16 at 7:48














                        • 1





                          and if the key is dynamic?

                          – Stefano Saitta
                          Jun 2 '16 at 10:45






                        • 1





                          Well, you should know which property of the given item/object should be used as key and which as value no? But if we assume that wfirst prop is always the key and second the value we could use a callback function like this: function(obj,item){ var keys = item.keys(); obj[item[keys[0]]] = item[keys[0]]; return obj; }

                          – GreQ
                          Jun 24 '16 at 7:33













                        • Correction of callback above: code var obj = arr.reduce(function(obj,item){ var keys = Object.keys(item); obj[item[keys[0]]] = item[keys[1]]; return obj; },{});

                          – GreQ
                          Jun 24 '16 at 7:48








                        1




                        1





                        and if the key is dynamic?

                        – Stefano Saitta
                        Jun 2 '16 at 10:45





                        and if the key is dynamic?

                        – Stefano Saitta
                        Jun 2 '16 at 10:45




                        1




                        1





                        Well, you should know which property of the given item/object should be used as key and which as value no? But if we assume that wfirst prop is always the key and second the value we could use a callback function like this: function(obj,item){ var keys = item.keys(); obj[item[keys[0]]] = item[keys[0]]; return obj; }

                        – GreQ
                        Jun 24 '16 at 7:33







                        Well, you should know which property of the given item/object should be used as key and which as value no? But if we assume that wfirst prop is always the key and second the value we could use a callback function like this: function(obj,item){ var keys = item.keys(); obj[item[keys[0]]] = item[keys[0]]; return obj; }

                        – GreQ
                        Jun 24 '16 at 7:33















                        Correction of callback above: code var obj = arr.reduce(function(obj,item){ var keys = Object.keys(item); obj[item[keys[0]]] = item[keys[1]]; return obj; },{});

                        – GreQ
                        Jun 24 '16 at 7:48





                        Correction of callback above: code var obj = arr.reduce(function(obj,item){ var keys = Object.keys(item); obj[item[keys[0]]] = item[keys[1]]; return obj; },{});

                        – GreQ
                        Jun 24 '16 at 7:48











                        33














                        Tiny ES6 solution can look like:



                        var arr = [{key:"11", value:"1100"},{key:"22", value:"2200"}];
                        var object = arr.reduce(
                        (obj, item) => Object.assign(obj, {[item.key]: item.value}) ,{});


                        Also, if you use object spread, than it can look like:



                        var object = arr.reduce((obj, item) => ({...obj, {[item.key]: item.value}}) ,{});


                        One more solution that is 99% faster is(tested on jsperf):



                        var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});


                        Here we benefit from comma operator, it evaluates all expression before comma and returns a last one(after last comma). So we don't copy obj each time, rather assigning new property to it.






                        share|improve this answer





















                        • 1





                          The simplest answer of all, yet the most elegant too

                          – Jeremy Belolo
                          Nov 9 '17 at 18:49













                        • Loved the one! var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});

                          – Sohail
                          Aug 21 '18 at 13:36
















                        33














                        Tiny ES6 solution can look like:



                        var arr = [{key:"11", value:"1100"},{key:"22", value:"2200"}];
                        var object = arr.reduce(
                        (obj, item) => Object.assign(obj, {[item.key]: item.value}) ,{});


                        Also, if you use object spread, than it can look like:



                        var object = arr.reduce((obj, item) => ({...obj, {[item.key]: item.value}}) ,{});


                        One more solution that is 99% faster is(tested on jsperf):



                        var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});


                        Here we benefit from comma operator, it evaluates all expression before comma and returns a last one(after last comma). So we don't copy obj each time, rather assigning new property to it.






                        share|improve this answer





















                        • 1





                          The simplest answer of all, yet the most elegant too

                          – Jeremy Belolo
                          Nov 9 '17 at 18:49













                        • Loved the one! var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});

                          – Sohail
                          Aug 21 '18 at 13:36














                        33












                        33








                        33







                        Tiny ES6 solution can look like:



                        var arr = [{key:"11", value:"1100"},{key:"22", value:"2200"}];
                        var object = arr.reduce(
                        (obj, item) => Object.assign(obj, {[item.key]: item.value}) ,{});


                        Also, if you use object spread, than it can look like:



                        var object = arr.reduce((obj, item) => ({...obj, {[item.key]: item.value}}) ,{});


                        One more solution that is 99% faster is(tested on jsperf):



                        var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});


                        Here we benefit from comma operator, it evaluates all expression before comma and returns a last one(after last comma). So we don't copy obj each time, rather assigning new property to it.






                        share|improve this answer















                        Tiny ES6 solution can look like:



                        var arr = [{key:"11", value:"1100"},{key:"22", value:"2200"}];
                        var object = arr.reduce(
                        (obj, item) => Object.assign(obj, {[item.key]: item.value}) ,{});


                        Also, if you use object spread, than it can look like:



                        var object = arr.reduce((obj, item) => ({...obj, {[item.key]: item.value}}) ,{});


                        One more solution that is 99% faster is(tested on jsperf):



                        var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});


                        Here we benefit from comma operator, it evaluates all expression before comma and returns a last one(after last comma). So we don't copy obj each time, rather assigning new property to it.







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Aug 7 '17 at 14:16

























                        answered Jun 2 '17 at 9:14









                        Shevchenko ViktorShevchenko Viktor

                        889615




                        889615








                        • 1





                          The simplest answer of all, yet the most elegant too

                          – Jeremy Belolo
                          Nov 9 '17 at 18:49













                        • Loved the one! var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});

                          – Sohail
                          Aug 21 '18 at 13:36














                        • 1





                          The simplest answer of all, yet the most elegant too

                          – Jeremy Belolo
                          Nov 9 '17 at 18:49













                        • Loved the one! var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});

                          – Sohail
                          Aug 21 '18 at 13:36








                        1




                        1





                        The simplest answer of all, yet the most elegant too

                        – Jeremy Belolo
                        Nov 9 '17 at 18:49







                        The simplest answer of all, yet the most elegant too

                        – Jeremy Belolo
                        Nov 9 '17 at 18:49















                        Loved the one! var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});

                        – Sohail
                        Aug 21 '18 at 13:36





                        Loved the one! var object = arr.reduce((obj, item) => (obj[item.key] = item.value, obj) ,{});

                        – Sohail
                        Aug 21 '18 at 13:36











                        7














                        Trying to fix this answer, this should do it:






                        var array = [
                        {key:'k1',value:'v1'},
                        {key:'k2',value:'v2'},
                        {key:'k3',value:'v3'}
                        ];
                        var mapped = array .map(item => ({ [item.key]: item.value }) );
                        var newObj = Object.assign({}, ...mapped );
                        console.log(newObj );








                        One-liner:

                        var newObj = Object.assign({}, ...(array.map(item => ({ [item.key]: item.value }) )));





                        share|improve this answer






























                          7














                          Trying to fix this answer, this should do it:






                          var array = [
                          {key:'k1',value:'v1'},
                          {key:'k2',value:'v2'},
                          {key:'k3',value:'v3'}
                          ];
                          var mapped = array .map(item => ({ [item.key]: item.value }) );
                          var newObj = Object.assign({}, ...mapped );
                          console.log(newObj );








                          One-liner:

                          var newObj = Object.assign({}, ...(array.map(item => ({ [item.key]: item.value }) )));





                          share|improve this answer




























                            7












                            7








                            7







                            Trying to fix this answer, this should do it:






                            var array = [
                            {key:'k1',value:'v1'},
                            {key:'k2',value:'v2'},
                            {key:'k3',value:'v3'}
                            ];
                            var mapped = array .map(item => ({ [item.key]: item.value }) );
                            var newObj = Object.assign({}, ...mapped );
                            console.log(newObj );








                            One-liner:

                            var newObj = Object.assign({}, ...(array.map(item => ({ [item.key]: item.value }) )));





                            share|improve this answer















                            Trying to fix this answer, this should do it:






                            var array = [
                            {key:'k1',value:'v1'},
                            {key:'k2',value:'v2'},
                            {key:'k3',value:'v3'}
                            ];
                            var mapped = array .map(item => ({ [item.key]: item.value }) );
                            var newObj = Object.assign({}, ...mapped );
                            console.log(newObj );








                            One-liner:

                            var newObj = Object.assign({}, ...(array.map(item => ({ [item.key]: item.value }) )));





                            var array = [
                            {key:'k1',value:'v1'},
                            {key:'k2',value:'v2'},
                            {key:'k3',value:'v3'}
                            ];
                            var mapped = array .map(item => ({ [item.key]: item.value }) );
                            var newObj = Object.assign({}, ...mapped );
                            console.log(newObj );





                            var array = [
                            {key:'k1',value:'v1'},
                            {key:'k2',value:'v2'},
                            {key:'k3',value:'v3'}
                            ];
                            var mapped = array .map(item => ({ [item.key]: item.value }) );
                            var newObj = Object.assign({}, ...mapped );
                            console.log(newObj );






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 13 '18 at 3:14

























                            answered Mar 13 '18 at 3:02









                            FirstOneFirstOne

                            3,97341533




                            3,97341533























                                5














                                A clean way to do this using modern JavaScript is as follows:



                                const array = [
                                { name: "something", value: "something" },
                                { name: "somethingElse", value: "something else" },
                                ];

                                const newObject = Object.assign({}, ...array.map(item => ({ [item.name]: item.value })));

                                // >> { something: "something", somethingElse: "something else" }





                                share|improve this answer




























                                  5














                                  A clean way to do this using modern JavaScript is as follows:



                                  const array = [
                                  { name: "something", value: "something" },
                                  { name: "somethingElse", value: "something else" },
                                  ];

                                  const newObject = Object.assign({}, ...array.map(item => ({ [item.name]: item.value })));

                                  // >> { something: "something", somethingElse: "something else" }





                                  share|improve this answer


























                                    5












                                    5








                                    5







                                    A clean way to do this using modern JavaScript is as follows:



                                    const array = [
                                    { name: "something", value: "something" },
                                    { name: "somethingElse", value: "something else" },
                                    ];

                                    const newObject = Object.assign({}, ...array.map(item => ({ [item.name]: item.value })));

                                    // >> { something: "something", somethingElse: "something else" }





                                    share|improve this answer













                                    A clean way to do this using modern JavaScript is as follows:



                                    const array = [
                                    { name: "something", value: "something" },
                                    { name: "somethingElse", value: "something else" },
                                    ];

                                    const newObject = Object.assign({}, ...array.map(item => ({ [item.name]: item.value })));

                                    // >> { something: "something", somethingElse: "something else" }






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Oct 9 '18 at 11:11









                                    Hedley SmithHedley Smith

                                    47166




                                    47166























                                        4














                                        Use lodash!



                                        const obj = _.keyBy(arrayOfObjects, 'keyName')





                                        share|improve this answer




























                                          4














                                          Use lodash!



                                          const obj = _.keyBy(arrayOfObjects, 'keyName')





                                          share|improve this answer


























                                            4












                                            4








                                            4







                                            Use lodash!



                                            const obj = _.keyBy(arrayOfObjects, 'keyName')





                                            share|improve this answer













                                            Use lodash!



                                            const obj = _.keyBy(arrayOfObjects, 'keyName')






                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Jun 5 '16 at 13:16









                                            ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhahhhhhhhhhhhhhhhhhhhhhhhhhhhhh

                                            750179




                                            750179























                                                2














                                                Using Underscore.js:



                                                var myArray = [
                                                Object { key="11", value="1100", $$hashKey="00X"},
                                                Object { key="22", value="2200", $$hashKey="018"}
                                                ];
                                                var myObj = _.object(_.pluck(myArray, 'key'), _.pluck(myArray, 'value'));





                                                share|improve this answer




























                                                  2














                                                  Using Underscore.js:



                                                  var myArray = [
                                                  Object { key="11", value="1100", $$hashKey="00X"},
                                                  Object { key="22", value="2200", $$hashKey="018"}
                                                  ];
                                                  var myObj = _.object(_.pluck(myArray, 'key'), _.pluck(myArray, 'value'));





                                                  share|improve this answer


























                                                    2












                                                    2








                                                    2







                                                    Using Underscore.js:



                                                    var myArray = [
                                                    Object { key="11", value="1100", $$hashKey="00X"},
                                                    Object { key="22", value="2200", $$hashKey="018"}
                                                    ];
                                                    var myObj = _.object(_.pluck(myArray, 'key'), _.pluck(myArray, 'value'));





                                                    share|improve this answer













                                                    Using Underscore.js:



                                                    var myArray = [
                                                    Object { key="11", value="1100", $$hashKey="00X"},
                                                    Object { key="22", value="2200", $$hashKey="018"}
                                                    ];
                                                    var myObj = _.object(_.pluck(myArray, 'key'), _.pluck(myArray, 'value'));






                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered May 24 '16 at 3:52









                                                    PaulPaul

                                                    14.7k106086




                                                    14.7k106086























                                                        0














                                                        Here you go:



                                                        var arr = [{ key: "11", value: "1100" }, { key: "22", value: "2200" }];
                                                        var result = {};
                                                        for (var i=0, len=arr.length; i < len; i++) {
                                                        result[arr[i].key] = arr[i].value;
                                                        }
                                                        console.log(result); // {11: "1000", 22: "2200"}





                                                        share|improve this answer
























                                                        • This surprisingly resembles the answer someone posted like 5 minutes ago

                                                          – Alexander
                                                          Nov 9 '13 at 10:04






                                                        • 1





                                                          Because that's how you solve this problem. About the naming for example: array is a reserved keyword so people use arr instead. etc.

                                                          – pstadler
                                                          Nov 9 '13 at 10:36


















                                                        0














                                                        Here you go:



                                                        var arr = [{ key: "11", value: "1100" }, { key: "22", value: "2200" }];
                                                        var result = {};
                                                        for (var i=0, len=arr.length; i < len; i++) {
                                                        result[arr[i].key] = arr[i].value;
                                                        }
                                                        console.log(result); // {11: "1000", 22: "2200"}





                                                        share|improve this answer
























                                                        • This surprisingly resembles the answer someone posted like 5 minutes ago

                                                          – Alexander
                                                          Nov 9 '13 at 10:04






                                                        • 1





                                                          Because that's how you solve this problem. About the naming for example: array is a reserved keyword so people use arr instead. etc.

                                                          – pstadler
                                                          Nov 9 '13 at 10:36
















                                                        0












                                                        0








                                                        0







                                                        Here you go:



                                                        var arr = [{ key: "11", value: "1100" }, { key: "22", value: "2200" }];
                                                        var result = {};
                                                        for (var i=0, len=arr.length; i < len; i++) {
                                                        result[arr[i].key] = arr[i].value;
                                                        }
                                                        console.log(result); // {11: "1000", 22: "2200"}





                                                        share|improve this answer













                                                        Here you go:



                                                        var arr = [{ key: "11", value: "1100" }, { key: "22", value: "2200" }];
                                                        var result = {};
                                                        for (var i=0, len=arr.length; i < len; i++) {
                                                        result[arr[i].key] = arr[i].value;
                                                        }
                                                        console.log(result); // {11: "1000", 22: "2200"}






                                                        share|improve this answer












                                                        share|improve this answer



                                                        share|improve this answer










                                                        answered Nov 9 '13 at 10:00









                                                        pstadlerpstadler

                                                        551418




                                                        551418













                                                        • This surprisingly resembles the answer someone posted like 5 minutes ago

                                                          – Alexander
                                                          Nov 9 '13 at 10:04






                                                        • 1





                                                          Because that's how you solve this problem. About the naming for example: array is a reserved keyword so people use arr instead. etc.

                                                          – pstadler
                                                          Nov 9 '13 at 10:36





















                                                        • This surprisingly resembles the answer someone posted like 5 minutes ago

                                                          – Alexander
                                                          Nov 9 '13 at 10:04






                                                        • 1





                                                          Because that's how you solve this problem. About the naming for example: array is a reserved keyword so people use arr instead. etc.

                                                          – pstadler
                                                          Nov 9 '13 at 10:36



















                                                        This surprisingly resembles the answer someone posted like 5 minutes ago

                                                        – Alexander
                                                        Nov 9 '13 at 10:04





                                                        This surprisingly resembles the answer someone posted like 5 minutes ago

                                                        – Alexander
                                                        Nov 9 '13 at 10:04




                                                        1




                                                        1





                                                        Because that's how you solve this problem. About the naming for example: array is a reserved keyword so people use arr instead. etc.

                                                        – pstadler
                                                        Nov 9 '13 at 10:36







                                                        Because that's how you solve this problem. About the naming for example: array is a reserved keyword so people use arr instead. etc.

                                                        – pstadler
                                                        Nov 9 '13 at 10:36













                                                        0














                                                        Here's how to dynamically accept the above as a string and interpolate it into an object:



                                                        var stringObject = '[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]';

                                                        function interpolateStringObject(stringObject) {
                                                        var jsObj = {};
                                                        var processedObj = stringObject.split("[Object { ");
                                                        processedObj = processedObj[1].split("},");
                                                        $.each(processedObj, function (i, v) {
                                                        jsObj[v.split("key=")[1].split(",")[0]] = v.split("value=")[1].split(",")[0].replace(/"/g,'');
                                                        });

                                                        return jsObj
                                                        }

                                                        var t = interpolateStringObject(stringObject); //t is the object you want


                                                        http://jsfiddle.net/3QKmX/1/






                                                        share|improve this answer




























                                                          0














                                                          Here's how to dynamically accept the above as a string and interpolate it into an object:



                                                          var stringObject = '[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]';

                                                          function interpolateStringObject(stringObject) {
                                                          var jsObj = {};
                                                          var processedObj = stringObject.split("[Object { ");
                                                          processedObj = processedObj[1].split("},");
                                                          $.each(processedObj, function (i, v) {
                                                          jsObj[v.split("key=")[1].split(",")[0]] = v.split("value=")[1].split(",")[0].replace(/"/g,'');
                                                          });

                                                          return jsObj
                                                          }

                                                          var t = interpolateStringObject(stringObject); //t is the object you want


                                                          http://jsfiddle.net/3QKmX/1/






                                                          share|improve this answer


























                                                            0












                                                            0








                                                            0







                                                            Here's how to dynamically accept the above as a string and interpolate it into an object:



                                                            var stringObject = '[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]';

                                                            function interpolateStringObject(stringObject) {
                                                            var jsObj = {};
                                                            var processedObj = stringObject.split("[Object { ");
                                                            processedObj = processedObj[1].split("},");
                                                            $.each(processedObj, function (i, v) {
                                                            jsObj[v.split("key=")[1].split(",")[0]] = v.split("value=")[1].split(",")[0].replace(/"/g,'');
                                                            });

                                                            return jsObj
                                                            }

                                                            var t = interpolateStringObject(stringObject); //t is the object you want


                                                            http://jsfiddle.net/3QKmX/1/






                                                            share|improve this answer













                                                            Here's how to dynamically accept the above as a string and interpolate it into an object:



                                                            var stringObject = '[Object { key="11", value="1100", $$hashKey="00X"}, Object { key="22", value="2200", $$hashKey="018"}]';

                                                            function interpolateStringObject(stringObject) {
                                                            var jsObj = {};
                                                            var processedObj = stringObject.split("[Object { ");
                                                            processedObj = processedObj[1].split("},");
                                                            $.each(processedObj, function (i, v) {
                                                            jsObj[v.split("key=")[1].split(",")[0]] = v.split("value=")[1].split(",")[0].replace(/"/g,'');
                                                            });

                                                            return jsObj
                                                            }

                                                            var t = interpolateStringObject(stringObject); //t is the object you want


                                                            http://jsfiddle.net/3QKmX/1/







                                                            share|improve this answer












                                                            share|improve this answer



                                                            share|improve this answer










                                                            answered Nov 9 '13 at 10:14









                                                            silicakessilicakes

                                                            1,90611527




                                                            1,90611527























                                                                0

















                                                                // original
                                                                var arr = [{
                                                                key: '11',
                                                                value: '1100',
                                                                $$hashKey: '00X'
                                                                },
                                                                {
                                                                key: '22',
                                                                value: '2200',
                                                                $$hashKey: '018'
                                                                }
                                                                ];

                                                                // My solution
                                                                var obj = {};
                                                                for (let i = 0; i < arr.length; i++) {
                                                                obj[arr[i].key] = arr[i].value;
                                                                }
                                                                console.log(obj)








                                                                share|improve this answer


























                                                                • While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.

                                                                  – Roshana Pitigala
                                                                  Jul 4 '18 at 18:23
















                                                                0

















                                                                // original
                                                                var arr = [{
                                                                key: '11',
                                                                value: '1100',
                                                                $$hashKey: '00X'
                                                                },
                                                                {
                                                                key: '22',
                                                                value: '2200',
                                                                $$hashKey: '018'
                                                                }
                                                                ];

                                                                // My solution
                                                                var obj = {};
                                                                for (let i = 0; i < arr.length; i++) {
                                                                obj[arr[i].key] = arr[i].value;
                                                                }
                                                                console.log(obj)








                                                                share|improve this answer


























                                                                • While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.

                                                                  – Roshana Pitigala
                                                                  Jul 4 '18 at 18:23














                                                                0












                                                                0








                                                                0










                                                                // original
                                                                var arr = [{
                                                                key: '11',
                                                                value: '1100',
                                                                $$hashKey: '00X'
                                                                },
                                                                {
                                                                key: '22',
                                                                value: '2200',
                                                                $$hashKey: '018'
                                                                }
                                                                ];

                                                                // My solution
                                                                var obj = {};
                                                                for (let i = 0; i < arr.length; i++) {
                                                                obj[arr[i].key] = arr[i].value;
                                                                }
                                                                console.log(obj)








                                                                share|improve this answer


















                                                                // original
                                                                var arr = [{
                                                                key: '11',
                                                                value: '1100',
                                                                $$hashKey: '00X'
                                                                },
                                                                {
                                                                key: '22',
                                                                value: '2200',
                                                                $$hashKey: '018'
                                                                }
                                                                ];

                                                                // My solution
                                                                var obj = {};
                                                                for (let i = 0; i < arr.length; i++) {
                                                                obj[arr[i].key] = arr[i].value;
                                                                }
                                                                console.log(obj)








                                                                // original
                                                                var arr = [{
                                                                key: '11',
                                                                value: '1100',
                                                                $$hashKey: '00X'
                                                                },
                                                                {
                                                                key: '22',
                                                                value: '2200',
                                                                $$hashKey: '018'
                                                                }
                                                                ];

                                                                // My solution
                                                                var obj = {};
                                                                for (let i = 0; i < arr.length; i++) {
                                                                obj[arr[i].key] = arr[i].value;
                                                                }
                                                                console.log(obj)





                                                                // original
                                                                var arr = [{
                                                                key: '11',
                                                                value: '1100',
                                                                $$hashKey: '00X'
                                                                },
                                                                {
                                                                key: '22',
                                                                value: '2200',
                                                                $$hashKey: '018'
                                                                }
                                                                ];

                                                                // My solution
                                                                var obj = {};
                                                                for (let i = 0; i < arr.length; i++) {
                                                                obj[arr[i].key] = arr[i].value;
                                                                }
                                                                console.log(obj)






                                                                share|improve this answer














                                                                share|improve this answer



                                                                share|improve this answer








                                                                edited Jul 4 '18 at 18:24









                                                                Roshana Pitigala

                                                                4,69462448




                                                                4,69462448










                                                                answered Jul 4 '18 at 13:39









                                                                omermindivanliomermindivanli

                                                                12




                                                                12













                                                                • While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.

                                                                  – Roshana Pitigala
                                                                  Jul 4 '18 at 18:23



















                                                                • While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.

                                                                  – Roshana Pitigala
                                                                  Jul 4 '18 at 18:23

















                                                                While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.

                                                                – Roshana Pitigala
                                                                Jul 4 '18 at 18:23





                                                                While this may answer the question it's better to add some description on how this answer may help to solve the issue. Please read How do I write a good answer to know more.

                                                                – Roshana Pitigala
                                                                Jul 4 '18 at 18:23











                                                                -1














                                                                        var obj = [
                                                                {id: 1 , name : 'gaju' , class : 'kv'},
                                                                {id: 2 , name : 'tushar' , class : 'Super'}
                                                                ];

                                                                function conv(obj,arg){
                                                                var temp= {};
                                                                var output= {}
                                                                for(key in obj){
                                                                temp[key] = obj[key];
                                                                };

                                                                var i=0;
                                                                for(key in temp){
                                                                var aa = {};
                                                                var value = temp[key][arg];
                                                                aa[value] = temp[i];
                                                                //console.log(aa[value][arg] );
                                                                output[aa[value][arg]]= aa[value];
                                                                i++;
                                                                }

                                                                console.log(output);
                                                                }

                                                                calling function

                                                                conv(obj,'class');





                                                                share|improve this answer




























                                                                  -1














                                                                          var obj = [
                                                                  {id: 1 , name : 'gaju' , class : 'kv'},
                                                                  {id: 2 , name : 'tushar' , class : 'Super'}
                                                                  ];

                                                                  function conv(obj,arg){
                                                                  var temp= {};
                                                                  var output= {}
                                                                  for(key in obj){
                                                                  temp[key] = obj[key];
                                                                  };

                                                                  var i=0;
                                                                  for(key in temp){
                                                                  var aa = {};
                                                                  var value = temp[key][arg];
                                                                  aa[value] = temp[i];
                                                                  //console.log(aa[value][arg] );
                                                                  output[aa[value][arg]]= aa[value];
                                                                  i++;
                                                                  }

                                                                  console.log(output);
                                                                  }

                                                                  calling function

                                                                  conv(obj,'class');





                                                                  share|improve this answer


























                                                                    -1












                                                                    -1








                                                                    -1







                                                                            var obj = [
                                                                    {id: 1 , name : 'gaju' , class : 'kv'},
                                                                    {id: 2 , name : 'tushar' , class : 'Super'}
                                                                    ];

                                                                    function conv(obj,arg){
                                                                    var temp= {};
                                                                    var output= {}
                                                                    for(key in obj){
                                                                    temp[key] = obj[key];
                                                                    };

                                                                    var i=0;
                                                                    for(key in temp){
                                                                    var aa = {};
                                                                    var value = temp[key][arg];
                                                                    aa[value] = temp[i];
                                                                    //console.log(aa[value][arg] );
                                                                    output[aa[value][arg]]= aa[value];
                                                                    i++;
                                                                    }

                                                                    console.log(output);
                                                                    }

                                                                    calling function

                                                                    conv(obj,'class');





                                                                    share|improve this answer













                                                                            var obj = [
                                                                    {id: 1 , name : 'gaju' , class : 'kv'},
                                                                    {id: 2 , name : 'tushar' , class : 'Super'}
                                                                    ];

                                                                    function conv(obj,arg){
                                                                    var temp= {};
                                                                    var output= {}
                                                                    for(key in obj){
                                                                    temp[key] = obj[key];
                                                                    };

                                                                    var i=0;
                                                                    for(key in temp){
                                                                    var aa = {};
                                                                    var value = temp[key][arg];
                                                                    aa[value] = temp[i];
                                                                    //console.log(aa[value][arg] );
                                                                    output[aa[value][arg]]= aa[value];
                                                                    i++;
                                                                    }

                                                                    console.log(output);
                                                                    }

                                                                    calling function

                                                                    conv(obj,'class');






                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Nov 13 '18 at 10:32









                                                                    Gajender SinghGajender Singh

                                                                    32525




                                                                    32525






























                                                                        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%2f19874555%2fhow-do-i-convert-array-of-objects-into-one-object-in-javascript%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

                                                                        Coverage of Google Street View

                                                                        Full-time equivalent

                                                                        Surfing