Convert a json array of objects into a different format2019 Community Moderator ElectionJavascript efficiency: 'for' vs 'forEach'Detecting an undefined object propertyWhat is the most efficient way to deep clone an object in JavaScript?How do I check if an array includes an object in JavaScript?Can comments be used in JSON?What is the correct JSON content type?Checking if a key exists in a JavaScript object?Why does Google prepend while(1); to their JSON responses?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?

Counting all the hearts

Declaring and defining template, and specialising them

Does a warlock using the Darkness/Devil's Sight combo still have advantage on ranged attacks against a target outside the Darkness?

How is the wildcard * interpreted as a command?

weren't playing vs didn't play

Is "history" a male-biased word ("his+story")?

Is it possible to avoid unpacking when merging Association?

How many characters using PHB rules does it take to be able to have access to any PHB spell at the start of an adventuring day?

What are actual Tesla M60 models used by AWS?

Shifting between bemols (flats) and diesis (sharps)in the key signature

Accountant/ lawyer will not return my call

Should I tell my boss the work he did was worthless

When traveling to Europe from North America, do I need to purchase a different power strip?

Are all players supposed to be able to see each others' character sheets?

How to secure an aircraft at a transient parking space?

If I receive an SOS signal, what is the proper response?

Why would one plane in this picture not have gear down yet?

Definition of Statistic

How can I ensure my trip to the UK will not have to be cancelled because of Brexit?

Vocabulary for giving just numbers, not a full answer

Find longest word in a string: are any of these algorithms good?

What was the Kree's motivation in Captain Marvel?

Intuition behind counterexample of Euler's sum of powers conjecture

Are there historical instances of the capital of a colonising country being temporarily or permanently shifted to one of its colonies?



Convert a json array of objects into a different format



2019 Community Moderator ElectionJavascript efficiency: 'for' vs 'forEach'Detecting an undefined object propertyWhat is the most efficient way to deep clone an object in JavaScript?How do I check if an array includes an object in JavaScript?Can comments be used in JSON?What is the correct JSON content type?Checking if a key exists in a JavaScript object?Why does Google prepend while(1); to their JSON responses?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?










0















How do I convert the following sample response data to the desired JSON format listed below? Thank you.



My logic



arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )


My current response data



arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
"'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]


Desired JSON format



arr = [

id: 0,
title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
,

id: 1,
title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"

]









share|improve this question




























    0















    How do I convert the following sample response data to the desired JSON format listed below? Thank you.



    My logic



    arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )


    My current response data



    arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
    "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]


    Desired JSON format



    arr = [

    id: 0,
    title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
    ,

    id: 1,
    title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"

    ]









    share|improve this question


























      0












      0








      0








      How do I convert the following sample response data to the desired JSON format listed below? Thank you.



      My logic



      arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )


      My current response data



      arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
      "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]


      Desired JSON format



      arr = [

      id: 0,
      title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
      ,

      id: 1,
      title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"

      ]









      share|improve this question
















      How do I convert the following sample response data to the desired JSON format listed below? Thank you.



      My logic



      arr = arr.map((e) => e.title = JSON.parse(e.title.replace(/'/g, '"')).title; return e; )


      My current response data



      arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
      "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]


      Desired JSON format



      arr = [

      id: 0,
      title: "'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'YAHSHUA', 'instruction': '?', 'created_at': '2019-03-06'",
      ,

      id: 1,
      title: "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Exam2', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"

      ]






      javascript arrays json object






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 2 days ago









      georgeawg

      33.9k105270




      33.9k105270










      asked Mar 7 at 6:39









      Jhon CaylogJhon Caylog

      8410




      8410






















          10 Answers
          10






          active

          oldest

          votes


















          2














          Try below code,



          Because if you are using forEach or something it will affect your code performance.



          I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.



          For your reference Javascript efficiency: 'for' vs 'forEach'.



          var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
          ];

          var result = [];

          for(let i=0;i<arr.length;i++)
          result.push(id: i, title:arr[i]);


          console.log(result);


          For loop analysis report : https://github.com/dg92/Performance-Analysis-JS






          share|improve this answer
































            6














            Um, just



             arr.map((title, id) => ( title, id ))





            share|improve this answer






























              3














              You can use map() to return the desired output:






              const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
              "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

              const result = arr.map((item, index) => (
              id: index,
              title: item
              ));

              console.log(result);





              In this way, you return an array of objects that have a title property of type string. If you want to output the title value as an object, you can parse the value with JSON.parse():



              const result = arr.map((item, index) => (
              id: index,
              title: JSON.parse(item)
              ));





              share|improve this answer






























                2














                It's not difficult, you have to map the array as you were doing, and return the new object:






                arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                mapped = arr.map((elem, index) =>
                return (
                id: index,
                title: elem
                );
                );

                console.log(mapped);








                share|improve this answer






























                  2














                  use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement






                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                  let newArr =arr.map((currElement, index) =>
                  return "id":index,"title":currElement;
                  );

                  console.log(newArr);








                  share|improve this answer






























                    2














                    Using forEach loop create an object with required properties and replace the original object in the array






                    var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                    "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                    ]
                    arr.forEach((e, i) =>
                    arr[i] = id:i,title:e;
                    )
                    console.log(arr)








                    share|improve this answer






























                      2














                      try this






                      let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                      "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                      let newArr =arr.map((element, index) =>
                      return "id":index,"title":element;
                      );

                      console.log(newArr);








                      share|improve this answer








                      New contributor




                      Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.



























                        1














                         arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                        "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                        for (var k = 0; k < arr.length; k++)
                        arr[k] = 'id':k, 'title': arr[k] ;

                        console.log(arr);





                        share|improve this answer






























                          1














                          You can use .map where the index is the id:






                          const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],

                          res = arr.map((title, id) => (id, title));
                          console.log(res);








                          share|improve this answer
































                            1














                             var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                            "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                            var new_arr = [];

                            for(var i=0; i< arr.length; i++)
                            new_arr[i] = 'id':i, 'title':arr[i]


                            console.log(JSON.stringify(new_arr));





                            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%2f55037535%2fconvert-a-json-array-of-objects-into-a-different-format%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown

























                              10 Answers
                              10






                              active

                              oldest

                              votes








                              10 Answers
                              10






                              active

                              oldest

                              votes









                              active

                              oldest

                              votes






                              active

                              oldest

                              votes









                              2














                              Try below code,



                              Because if you are using forEach or something it will affect your code performance.



                              I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.



                              For your reference Javascript efficiency: 'for' vs 'forEach'.



                              var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                              "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                              ];

                              var result = [];

                              for(let i=0;i<arr.length;i++)
                              result.push(id: i, title:arr[i]);


                              console.log(result);


                              For loop analysis report : https://github.com/dg92/Performance-Analysis-JS






                              share|improve this answer





























                                2














                                Try below code,



                                Because if you are using forEach or something it will affect your code performance.



                                I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.



                                For your reference Javascript efficiency: 'for' vs 'forEach'.



                                var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                ];

                                var result = [];

                                for(let i=0;i<arr.length;i++)
                                result.push(id: i, title:arr[i]);


                                console.log(result);


                                For loop analysis report : https://github.com/dg92/Performance-Analysis-JS






                                share|improve this answer



























                                  2












                                  2








                                  2







                                  Try below code,



                                  Because if you are using forEach or something it will affect your code performance.



                                  I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.



                                  For your reference Javascript efficiency: 'for' vs 'forEach'.



                                  var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                  ];

                                  var result = [];

                                  for(let i=0;i<arr.length;i++)
                                  result.push(id: i, title:arr[i]);


                                  console.log(result);


                                  For loop analysis report : https://github.com/dg92/Performance-Analysis-JS






                                  share|improve this answer















                                  Try below code,



                                  Because if you are using forEach or something it will affect your code performance.



                                  I will recommend this way if you want to handle large data's. If you have less data then use other answers above to achieve your output with less code.



                                  For your reference Javascript efficiency: 'for' vs 'forEach'.



                                  var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                  ];

                                  var result = [];

                                  for(let i=0;i<arr.length;i++)
                                  result.push(id: i, title:arr[i]);


                                  console.log(result);


                                  For loop analysis report : https://github.com/dg92/Performance-Analysis-JS







                                  share|improve this answer














                                  share|improve this answer



                                  share|improve this answer








                                  edited Mar 7 at 7:11

























                                  answered Mar 7 at 6:53









                                  DineshDinesh

                                  4,89093675




                                  4,89093675























                                      6














                                      Um, just



                                       arr.map((title, id) => ( title, id ))





                                      share|improve this answer



























                                        6














                                        Um, just



                                         arr.map((title, id) => ( title, id ))





                                        share|improve this answer

























                                          6












                                          6








                                          6







                                          Um, just



                                           arr.map((title, id) => ( title, id ))





                                          share|improve this answer













                                          Um, just



                                           arr.map((title, id) => ( title, id ))






                                          share|improve this answer












                                          share|improve this answer



                                          share|improve this answer










                                          answered Mar 7 at 6:44









                                          Jonas WilmsJonas Wilms

                                          61.1k53255




                                          61.1k53255





















                                              3














                                              You can use map() to return the desired output:






                                              const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                              "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                              const result = arr.map((item, index) => (
                                              id: index,
                                              title: item
                                              ));

                                              console.log(result);





                                              In this way, you return an array of objects that have a title property of type string. If you want to output the title value as an object, you can parse the value with JSON.parse():



                                              const result = arr.map((item, index) => (
                                              id: index,
                                              title: JSON.parse(item)
                                              ));





                                              share|improve this answer



























                                                3














                                                You can use map() to return the desired output:






                                                const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                const result = arr.map((item, index) => (
                                                id: index,
                                                title: item
                                                ));

                                                console.log(result);





                                                In this way, you return an array of objects that have a title property of type string. If you want to output the title value as an object, you can parse the value with JSON.parse():



                                                const result = arr.map((item, index) => (
                                                id: index,
                                                title: JSON.parse(item)
                                                ));





                                                share|improve this answer

























                                                  3












                                                  3








                                                  3







                                                  You can use map() to return the desired output:






                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                  const result = arr.map((item, index) => (
                                                  id: index,
                                                  title: item
                                                  ));

                                                  console.log(result);





                                                  In this way, you return an array of objects that have a title property of type string. If you want to output the title value as an object, you can parse the value with JSON.parse():



                                                  const result = arr.map((item, index) => (
                                                  id: index,
                                                  title: JSON.parse(item)
                                                  ));





                                                  share|improve this answer













                                                  You can use map() to return the desired output:






                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                  const result = arr.map((item, index) => (
                                                  id: index,
                                                  title: item
                                                  ));

                                                  console.log(result);





                                                  In this way, you return an array of objects that have a title property of type string. If you want to output the title value as an object, you can parse the value with JSON.parse():



                                                  const result = arr.map((item, index) => (
                                                  id: index,
                                                  title: JSON.parse(item)
                                                  ));





                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                  const result = arr.map((item, index) => (
                                                  id: index,
                                                  title: item
                                                  ));

                                                  console.log(result);





                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                  const result = arr.map((item, index) => (
                                                  id: index,
                                                  title: item
                                                  ));

                                                  console.log(result);






                                                  share|improve this answer












                                                  share|improve this answer



                                                  share|improve this answer










                                                  answered Mar 7 at 6:44









                                                  kapantzakkapantzak

                                                  9,63442750




                                                  9,63442750





















                                                      2














                                                      It's not difficult, you have to map the array as you were doing, and return the new object:






                                                      arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                      "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                      mapped = arr.map((elem, index) =>
                                                      return (
                                                      id: index,
                                                      title: elem
                                                      );
                                                      );

                                                      console.log(mapped);








                                                      share|improve this answer



























                                                        2














                                                        It's not difficult, you have to map the array as you were doing, and return the new object:






                                                        arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                        "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                        mapped = arr.map((elem, index) =>
                                                        return (
                                                        id: index,
                                                        title: elem
                                                        );
                                                        );

                                                        console.log(mapped);








                                                        share|improve this answer

























                                                          2












                                                          2








                                                          2







                                                          It's not difficult, you have to map the array as you were doing, and return the new object:






                                                          arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                          mapped = arr.map((elem, index) =>
                                                          return (
                                                          id: index,
                                                          title: elem
                                                          );
                                                          );

                                                          console.log(mapped);








                                                          share|improve this answer













                                                          It's not difficult, you have to map the array as you were doing, and return the new object:






                                                          arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                          mapped = arr.map((elem, index) =>
                                                          return (
                                                          id: index,
                                                          title: elem
                                                          );
                                                          );

                                                          console.log(mapped);








                                                          arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                          mapped = arr.map((elem, index) =>
                                                          return (
                                                          id: index,
                                                          title: elem
                                                          );
                                                          );

                                                          console.log(mapped);





                                                          arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                          mapped = arr.map((elem, index) =>
                                                          return (
                                                          id: index,
                                                          title: elem
                                                          );
                                                          );

                                                          console.log(mapped);






                                                          share|improve this answer












                                                          share|improve this answer



                                                          share|improve this answer










                                                          answered Mar 7 at 6:44









                                                          JV LoboJV Lobo

                                                          2,97762140




                                                          2,97762140





















                                                              2














                                                              use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement






                                                              let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                              "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                              let newArr =arr.map((currElement, index) =>
                                                              return "id":index,"title":currElement;
                                                              );

                                                              console.log(newArr);








                                                              share|improve this answer



























                                                                2














                                                                use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement






                                                                let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                let newArr =arr.map((currElement, index) =>
                                                                return "id":index,"title":currElement;
                                                                );

                                                                console.log(newArr);








                                                                share|improve this answer

























                                                                  2












                                                                  2








                                                                  2







                                                                  use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement






                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                  let newArr =arr.map((currElement, index) =>
                                                                  return "id":index,"title":currElement;
                                                                  );

                                                                  console.log(newArr);








                                                                  share|improve this answer













                                                                  use currElement, index as the parameter of map then return the new object of "id":index,"title":currElement






                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                  let newArr =arr.map((currElement, index) =>
                                                                  return "id":index,"title":currElement;
                                                                  );

                                                                  console.log(newArr);








                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                  let newArr =arr.map((currElement, index) =>
                                                                  return "id":index,"title":currElement;
                                                                  );

                                                                  console.log(newArr);





                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                  let newArr =arr.map((currElement, index) =>
                                                                  return "id":index,"title":currElement;
                                                                  );

                                                                  console.log(newArr);






                                                                  share|improve this answer












                                                                  share|improve this answer



                                                                  share|improve this answer










                                                                  answered Mar 7 at 6:45









                                                                  Mohammad Ali RonyMohammad Ali Rony

                                                                  2,5341818




                                                                  2,5341818





















                                                                      2














                                                                      Using forEach loop create an object with required properties and replace the original object in the array






                                                                      var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                      "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                                                      ]
                                                                      arr.forEach((e, i) =>
                                                                      arr[i] = id:i,title:e;
                                                                      )
                                                                      console.log(arr)








                                                                      share|improve this answer



























                                                                        2














                                                                        Using forEach loop create an object with required properties and replace the original object in the array






                                                                        var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                        "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                                                        ]
                                                                        arr.forEach((e, i) =>
                                                                        arr[i] = id:i,title:e;
                                                                        )
                                                                        console.log(arr)








                                                                        share|improve this answer

























                                                                          2












                                                                          2








                                                                          2







                                                                          Using forEach loop create an object with required properties and replace the original object in the array






                                                                          var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                                                          ]
                                                                          arr.forEach((e, i) =>
                                                                          arr[i] = id:i,title:e;
                                                                          )
                                                                          console.log(arr)








                                                                          share|improve this answer













                                                                          Using forEach loop create an object with required properties and replace the original object in the array






                                                                          var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                                                          ]
                                                                          arr.forEach((e, i) =>
                                                                          arr[i] = id:i,title:e;
                                                                          )
                                                                          console.log(arr)








                                                                          var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                                                          ]
                                                                          arr.forEach((e, i) =>
                                                                          arr[i] = id:i,title:e;
                                                                          )
                                                                          console.log(arr)





                                                                          var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"
                                                                          ]
                                                                          arr.forEach((e, i) =>
                                                                          arr[i] = id:i,title:e;
                                                                          )
                                                                          console.log(arr)






                                                                          share|improve this answer












                                                                          share|improve this answer



                                                                          share|improve this answer










                                                                          answered Mar 7 at 6:46









                                                                          ellipsisellipsis

                                                                          7,8112929




                                                                          7,8112929





















                                                                              2














                                                                              try this






                                                                              let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                              "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                              let newArr =arr.map((element, index) =>
                                                                              return "id":index,"title":element;
                                                                              );

                                                                              console.log(newArr);








                                                                              share|improve this answer








                                                                              New contributor




                                                                              Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                              Check out our Code of Conduct.
























                                                                                2














                                                                                try this






                                                                                let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                let newArr =arr.map((element, index) =>
                                                                                return "id":index,"title":element;
                                                                                );

                                                                                console.log(newArr);








                                                                                share|improve this answer








                                                                                New contributor




                                                                                Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                Check out our Code of Conduct.






















                                                                                  2












                                                                                  2








                                                                                  2







                                                                                  try this






                                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                  let newArr =arr.map((element, index) =>
                                                                                  return "id":index,"title":element;
                                                                                  );

                                                                                  console.log(newArr);








                                                                                  share|improve this answer








                                                                                  New contributor




                                                                                  Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                  Check out our Code of Conduct.










                                                                                  try this






                                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                  let newArr =arr.map((element, index) =>
                                                                                  return "id":index,"title":element;
                                                                                  );

                                                                                  console.log(newArr);








                                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                  let newArr =arr.map((element, index) =>
                                                                                  return "id":index,"title":element;
                                                                                  );

                                                                                  console.log(newArr);





                                                                                  let arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                  "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                  let newArr =arr.map((element, index) =>
                                                                                  return "id":index,"title":element;
                                                                                  );

                                                                                  console.log(newArr);






                                                                                  share|improve this answer








                                                                                  New contributor




                                                                                  Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                  Check out our Code of Conduct.









                                                                                  share|improve this answer



                                                                                  share|improve this answer






                                                                                  New contributor




                                                                                  Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                  Check out our Code of Conduct.









                                                                                  answered Mar 7 at 15:12









                                                                                  Shahriar MahirShahriar Mahir

                                                                                  292




                                                                                  292




                                                                                  New contributor




                                                                                  Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                  Check out our Code of Conduct.





                                                                                  New contributor





                                                                                  Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                  Check out our Code of Conduct.






                                                                                  Shahriar Mahir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                                                                  Check out our Code of Conduct.





















                                                                                      1














                                                                                       arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                      "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                                                      for (var k = 0; k < arr.length; k++)
                                                                                      arr[k] = 'id':k, 'title': arr[k] ;

                                                                                      console.log(arr);





                                                                                      share|improve this answer



























                                                                                        1














                                                                                         arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                        "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                                                        for (var k = 0; k < arr.length; k++)
                                                                                        arr[k] = 'id':k, 'title': arr[k] ;

                                                                                        console.log(arr);





                                                                                        share|improve this answer

























                                                                                          1












                                                                                          1








                                                                                          1







                                                                                           arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                                                          for (var k = 0; k < arr.length; k++)
                                                                                          arr[k] = 'id':k, 'title': arr[k] ;

                                                                                          console.log(arr);





                                                                                          share|improve this answer













                                                                                           arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"]

                                                                                          for (var k = 0; k < arr.length; k++)
                                                                                          arr[k] = 'id':k, 'title': arr[k] ;

                                                                                          console.log(arr);






                                                                                          share|improve this answer












                                                                                          share|improve this answer



                                                                                          share|improve this answer










                                                                                          answered Mar 7 at 6:51









                                                                                          Murali NepalliMurali Nepalli

                                                                                          1635




                                                                                          1635





















                                                                                              1














                                                                                              You can use .map where the index is the id:






                                                                                              const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],

                                                                                              res = arr.map((title, id) => (id, title));
                                                                                              console.log(res);








                                                                                              share|improve this answer





























                                                                                                1














                                                                                                You can use .map where the index is the id:






                                                                                                const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],

                                                                                                res = arr.map((title, id) => (id, title));
                                                                                                console.log(res);








                                                                                                share|improve this answer



























                                                                                                  1












                                                                                                  1








                                                                                                  1







                                                                                                  You can use .map where the index is the id:






                                                                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],

                                                                                                  res = arr.map((title, id) => (id, title));
                                                                                                  console.log(res);








                                                                                                  share|improve this answer















                                                                                                  You can use .map where the index is the id:






                                                                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],

                                                                                                  res = arr.map((title, id) => (id, title));
                                                                                                  console.log(res);








                                                                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],

                                                                                                  res = arr.map((title, id) => (id, title));
                                                                                                  console.log(res);





                                                                                                  const arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'", "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"],

                                                                                                  res = arr.map((title, id) => (id, title));
                                                                                                  console.log(res);






                                                                                                  share|improve this answer














                                                                                                  share|improve this answer



                                                                                                  share|improve this answer








                                                                                                  edited Mar 7 at 6:51

























                                                                                                  answered Mar 7 at 6:44









                                                                                                  Nick ParsonsNick Parsons

                                                                                                  9,4682826




                                                                                                  9,4682826





















                                                                                                      1














                                                                                                       var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                                      "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                                      var new_arr = [];

                                                                                                      for(var i=0; i< arr.length; i++)
                                                                                                      new_arr[i] = 'id':i, 'title':arr[i]


                                                                                                      console.log(JSON.stringify(new_arr));





                                                                                                      share|improve this answer



























                                                                                                        1














                                                                                                         var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                                        "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                                        var new_arr = [];

                                                                                                        for(var i=0; i< arr.length; i++)
                                                                                                        new_arr[i] = 'id':i, 'title':arr[i]


                                                                                                        console.log(JSON.stringify(new_arr));





                                                                                                        share|improve this answer

























                                                                                                          1












                                                                                                          1








                                                                                                          1







                                                                                                           var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                                          var new_arr = [];

                                                                                                          for(var i=0; i< arr.length; i++)
                                                                                                          new_arr[i] = 'id':i, 'title':arr[i]


                                                                                                          console.log(JSON.stringify(new_arr));





                                                                                                          share|improve this answer













                                                                                                           var arr = ["'department': 'YOWI', 'timelimit': '01:05:02', 'sub_title': 'PRE-EMPLOYMENT ASSESSMENT TEST PART 8', 'id': 185, 'random_code': '50-76997961114', 'title': 'Hey', 'instruction': '?', 'created_at': '2019-03-06'",
                                                                                                          "'department': 'Department Exam 2', 'timelimit': '01:05:08', 'sub_title': 'Just a test exam 2', 'id': 142, 'random_code': '50-3910111611011', 'title': 'Assessment', 'instruction': 'Hey Jude', 'created_at': '2019-02-27'"];

                                                                                                          var new_arr = [];

                                                                                                          for(var i=0; i< arr.length; i++)
                                                                                                          new_arr[i] = 'id':i, 'title':arr[i]


                                                                                                          console.log(JSON.stringify(new_arr));






                                                                                                          share|improve this answer












                                                                                                          share|improve this answer



                                                                                                          share|improve this answer










                                                                                                          answered Mar 7 at 6:53









                                                                                                          Kausha ShahKausha Shah

                                                                                                          635




                                                                                                          635



























                                                                                                              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%2f55037535%2fconvert-a-json-array-of-objects-into-a-different-format%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

                                                                                                              Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                                                                                                              2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                                                                                                              Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme