What is the most efficient way of creating a sequence of timouts in JSON?2019 Community Moderator ElectionWhat is the most efficient way to deep clone an object in JavaScript?What is the best way to add options to a select from as a JS object with jQuery?What is the most efficient way to create HTML elements using jQuery?What is JSON and why would I use it?What is the correct JSON content type?Most efficient way to create a zero filled JavaScript array?What is JSONP, and why was it created?What is the best way to detect a mobile device in jQuery?What is the correct way to check for string equality in JavaScript?Is the recommendation to include CSS before JavaScript invalid?

How to terminate ping <dest> &

Should I be concerned about student access to a test bank?

Print a physical multiplication table

Is it true that good novels will automatically sell themselves on Amazon (and so on) and there is no need for one to waste time promoting?

Would it be believable to defy demographics in a story?

Why didn't Héctor fade away after this character died in the movie Coco?

Are dual Irish/British citizens bound by the 90/180 day rule when travelling in the EU after Brexit?

Loading the leaflet Map in Lightning Web Component

Practical application of matrices and determinants

If "dar" means "to give", what does "daros" mean?

How could an airship be repaired midflight?

Violin - Can double stops be played when the strings are not next to each other?

World War I as a war of liberals against authoritarians?

Can other pieces capture a threatening piece and prevent a checkmate?

What does "Four-F." mean?

What does Deadpool mean by "left the house in that shirt"?

Is there a creature that is resistant or immune to non-magical damage other than bludgeoning, slashing, and piercing?

Knife as defense against stray dogs

두음법칙 - When did North and South diverge in pronunciation of initial ㄹ?

How to generate binary array whose elements with values 1 are randomly drawn

Worshiping one God at a time?

Is there a hypothetical scenario that would make Earth uninhabitable for humans, but not for (the majority of) other animals?

Am I eligible for the Eurail Youth pass? I am 27.5 years old

Is honey really a supersaturated solution? Does heating to un-crystalize redissolve it or melt it?



What is the most efficient way of creating a sequence of timouts in JSON?



2019 Community Moderator ElectionWhat is the most efficient way to deep clone an object in JavaScript?What is the best way to add options to a select from as a JS object with jQuery?What is the most efficient way to create HTML elements using jQuery?What is JSON and why would I use it?What is the correct JSON content type?Most efficient way to create a zero filled JavaScript array?What is JSONP, and why was it created?What is the best way to detect a mobile device in jQuery?What is the correct way to check for string equality in JavaScript?Is the recommendation to include CSS before JavaScript invalid?










1















I receive a json object from server which looks something like that:



1000: "Paragraph 1",
2000: "Paragraph 2",
2500: "Paragraph 3",
...
11500: "Paragraph 20",


My task is to show these lines subsequently: the first one in 1 sec, the second in 2 seconds, the third in 2.5 seconds etc.



I can of course generate a series of setTimeout, but I wonder if there is more efficient way of doing this?










share|improve this question



















  • 5





    I wonder if this is a homework question that is showing us no existing effort at a solution.

    – Taplar
    Mar 7 at 17:24











  • No, you will need a series of timeouts.

    – James
    Mar 7 at 17:37











  • Wonder if you can assign a setInterval to a var/let. Each interval, update the interval time for setInterval ... never tried that but would be interesting. You'd also need to test if all values have been handled then clearInterval()

    – Ted Fitzpatrick
    Mar 7 at 17:39















1















I receive a json object from server which looks something like that:



1000: "Paragraph 1",
2000: "Paragraph 2",
2500: "Paragraph 3",
...
11500: "Paragraph 20",


My task is to show these lines subsequently: the first one in 1 sec, the second in 2 seconds, the third in 2.5 seconds etc.



I can of course generate a series of setTimeout, but I wonder if there is more efficient way of doing this?










share|improve this question



















  • 5





    I wonder if this is a homework question that is showing us no existing effort at a solution.

    – Taplar
    Mar 7 at 17:24











  • No, you will need a series of timeouts.

    – James
    Mar 7 at 17:37











  • Wonder if you can assign a setInterval to a var/let. Each interval, update the interval time for setInterval ... never tried that but would be interesting. You'd also need to test if all values have been handled then clearInterval()

    – Ted Fitzpatrick
    Mar 7 at 17:39













1












1








1








I receive a json object from server which looks something like that:



1000: "Paragraph 1",
2000: "Paragraph 2",
2500: "Paragraph 3",
...
11500: "Paragraph 20",


My task is to show these lines subsequently: the first one in 1 sec, the second in 2 seconds, the third in 2.5 seconds etc.



I can of course generate a series of setTimeout, but I wonder if there is more efficient way of doing this?










share|improve this question
















I receive a json object from server which looks something like that:



1000: "Paragraph 1",
2000: "Paragraph 2",
2500: "Paragraph 3",
...
11500: "Paragraph 20",


My task is to show these lines subsequently: the first one in 1 sec, the second in 2 seconds, the third in 2.5 seconds etc.



I can of course generate a series of setTimeout, but I wonder if there is more efficient way of doing this?







javascript json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 18:21









Jodast

1




1










asked Mar 7 at 17:23









Philipp ChapkovskiPhilipp Chapkovski

5671516




5671516







  • 5





    I wonder if this is a homework question that is showing us no existing effort at a solution.

    – Taplar
    Mar 7 at 17:24











  • No, you will need a series of timeouts.

    – James
    Mar 7 at 17:37











  • Wonder if you can assign a setInterval to a var/let. Each interval, update the interval time for setInterval ... never tried that but would be interesting. You'd also need to test if all values have been handled then clearInterval()

    – Ted Fitzpatrick
    Mar 7 at 17:39












  • 5





    I wonder if this is a homework question that is showing us no existing effort at a solution.

    – Taplar
    Mar 7 at 17:24











  • No, you will need a series of timeouts.

    – James
    Mar 7 at 17:37











  • Wonder if you can assign a setInterval to a var/let. Each interval, update the interval time for setInterval ... never tried that but would be interesting. You'd also need to test if all values have been handled then clearInterval()

    – Ted Fitzpatrick
    Mar 7 at 17:39







5




5





I wonder if this is a homework question that is showing us no existing effort at a solution.

– Taplar
Mar 7 at 17:24





I wonder if this is a homework question that is showing us no existing effort at a solution.

– Taplar
Mar 7 at 17:24













No, you will need a series of timeouts.

– James
Mar 7 at 17:37





No, you will need a series of timeouts.

– James
Mar 7 at 17:37













Wonder if you can assign a setInterval to a var/let. Each interval, update the interval time for setInterval ... never tried that but would be interesting. You'd also need to test if all values have been handled then clearInterval()

– Ted Fitzpatrick
Mar 7 at 17:39





Wonder if you can assign a setInterval to a var/let. Each interval, update the interval time for setInterval ... never tried that but would be interesting. You'd also need to test if all values have been handled then clearInterval()

– Ted Fitzpatrick
Mar 7 at 17:39












4 Answers
4






active

oldest

votes


















1














None of the answers so far pay heed to the OPs claim that he doesn't want to create multiple setTimeout or setInterval.



We really can create a single setInterval and get it to iterate through the JSON in intervals.



var data = 
1000: "Paragraph 1",
2000: "Paragraph 2",
2500: "Paragraph 3",
5000 : "Paragraph 5",
11500: "Paragraph 20"
;

var keys = Object.keys(data);
var i = 0;

var handle = setInterval(()=>

console.log(data[keys[i++]]);

if (i === keys.length)
clearInterval(handle)

, 250);





share|improve this answer






























    0














    While you tagged a Jquery .. So $.each() is a simple way to do that



    ES 5






    var Json = 
    1000: "Paragraph 1",
    2000: "Paragraph 2",
    2500: "Paragraph 3",
    5000 : "Paragraph 5",
    11500: "Paragraph 20"
    ;


    PrintResults(Json);


    function PrintResults(result)
    $.each(result , function(key , value)
    setTimeout(function()
    console.log('Time is: '+key+' .. Value is: '+value);
    , key);
    );

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





    Additional ES 6






    var Json = 
    1000: "Paragraph 1",
    2000: "Paragraph 2",
    2500: "Paragraph 3",
    5000 : "Paragraph 5",
    11500: "Paragraph 20"
    ;


    PrintResults(Json);


    function PrintResults(result)
    $.each(result , (key , value) =>
    setTimeout(() =>
    console.log(`Time is: $key .. Value is: $value`);
    , key);
    );

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>








    share|improve this answer
































      0














      If you wanted to show the lines using a consistent time difference between each you could use setTimeout's brother function, setInterval.



      If you want, you could use setInterval and use a function to change the interval time



      var waitTime = 1000;
      var myFunction = function()
      //your code to display a line of text

      clearInterval(interval);
      waitTime += 50; //make your changes to wait time
      interval = setInterval(myFunction, waitTime);

      var interval = setInterval(myFunction, waitTime);


      Lastly, you could use the jquery delay function, but this only works if you're using jquery effects to display the text. Read about it here: https://api.jquery.com/delay/



      Ultimately, these are options that will work, but using setTimeout is the cleanest way to solve your problem.






      share|improve this answer
































        0














        It can be done using javascript like this






        var obj = 
        1000: "Paragraph 1",
        2000: "Paragraph 2",
        2500: "Paragraph 3",
        11500: "Paragraph 20"


        function displayResults(obj)

        var time = Object.keys(obj);
        var val = Object.values(obj);
        time.forEach(function(item, index)
        setTimeout(function()
        console.log("The time is " + item + " The value is " + val[index]);
        , item);
        )



        displayResults(obj);








        share|improve this answer























        • You are creating multiple setTimeouts in this approach.See my answer.

          – Charlie H
          Mar 8 at 6:24












        • I understand. Thank you

          – Sachintha Nayanajith
          Mar 9 at 9:10










        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%2f55049605%2fwhat-is-the-most-efficient-way-of-creating-a-sequence-of-timouts-in-json%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        None of the answers so far pay heed to the OPs claim that he doesn't want to create multiple setTimeout or setInterval.



        We really can create a single setInterval and get it to iterate through the JSON in intervals.



        var data = 
        1000: "Paragraph 1",
        2000: "Paragraph 2",
        2500: "Paragraph 3",
        5000 : "Paragraph 5",
        11500: "Paragraph 20"
        ;

        var keys = Object.keys(data);
        var i = 0;

        var handle = setInterval(()=>

        console.log(data[keys[i++]]);

        if (i === keys.length)
        clearInterval(handle)

        , 250);





        share|improve this answer



























          1














          None of the answers so far pay heed to the OPs claim that he doesn't want to create multiple setTimeout or setInterval.



          We really can create a single setInterval and get it to iterate through the JSON in intervals.



          var data = 
          1000: "Paragraph 1",
          2000: "Paragraph 2",
          2500: "Paragraph 3",
          5000 : "Paragraph 5",
          11500: "Paragraph 20"
          ;

          var keys = Object.keys(data);
          var i = 0;

          var handle = setInterval(()=>

          console.log(data[keys[i++]]);

          if (i === keys.length)
          clearInterval(handle)

          , 250);





          share|improve this answer

























            1












            1








            1







            None of the answers so far pay heed to the OPs claim that he doesn't want to create multiple setTimeout or setInterval.



            We really can create a single setInterval and get it to iterate through the JSON in intervals.



            var data = 
            1000: "Paragraph 1",
            2000: "Paragraph 2",
            2500: "Paragraph 3",
            5000 : "Paragraph 5",
            11500: "Paragraph 20"
            ;

            var keys = Object.keys(data);
            var i = 0;

            var handle = setInterval(()=>

            console.log(data[keys[i++]]);

            if (i === keys.length)
            clearInterval(handle)

            , 250);





            share|improve this answer













            None of the answers so far pay heed to the OPs claim that he doesn't want to create multiple setTimeout or setInterval.



            We really can create a single setInterval and get it to iterate through the JSON in intervals.



            var data = 
            1000: "Paragraph 1",
            2000: "Paragraph 2",
            2500: "Paragraph 3",
            5000 : "Paragraph 5",
            11500: "Paragraph 20"
            ;

            var keys = Object.keys(data);
            var i = 0;

            var handle = setInterval(()=>

            console.log(data[keys[i++]]);

            if (i === keys.length)
            clearInterval(handle)

            , 250);






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 8 at 6:23









            Charlie HCharlie H

            9,58342753




            9,58342753























                0














                While you tagged a Jquery .. So $.each() is a simple way to do that



                ES 5






                var Json = 
                1000: "Paragraph 1",
                2000: "Paragraph 2",
                2500: "Paragraph 3",
                5000 : "Paragraph 5",
                11500: "Paragraph 20"
                ;


                PrintResults(Json);


                function PrintResults(result)
                $.each(result , function(key , value)
                setTimeout(function()
                console.log('Time is: '+key+' .. Value is: '+value);
                , key);
                );

                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





                Additional ES 6






                var Json = 
                1000: "Paragraph 1",
                2000: "Paragraph 2",
                2500: "Paragraph 3",
                5000 : "Paragraph 5",
                11500: "Paragraph 20"
                ;


                PrintResults(Json);


                function PrintResults(result)
                $.each(result , (key , value) =>
                setTimeout(() =>
                console.log(`Time is: $key .. Value is: $value`);
                , key);
                );

                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>








                share|improve this answer





























                  0














                  While you tagged a Jquery .. So $.each() is a simple way to do that



                  ES 5






                  var Json = 
                  1000: "Paragraph 1",
                  2000: "Paragraph 2",
                  2500: "Paragraph 3",
                  5000 : "Paragraph 5",
                  11500: "Paragraph 20"
                  ;


                  PrintResults(Json);


                  function PrintResults(result)
                  $.each(result , function(key , value)
                  setTimeout(function()
                  console.log('Time is: '+key+' .. Value is: '+value);
                  , key);
                  );

                  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





                  Additional ES 6






                  var Json = 
                  1000: "Paragraph 1",
                  2000: "Paragraph 2",
                  2500: "Paragraph 3",
                  5000 : "Paragraph 5",
                  11500: "Paragraph 20"
                  ;


                  PrintResults(Json);


                  function PrintResults(result)
                  $.each(result , (key , value) =>
                  setTimeout(() =>
                  console.log(`Time is: $key .. Value is: $value`);
                  , key);
                  );

                  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>








                  share|improve this answer



























                    0












                    0








                    0







                    While you tagged a Jquery .. So $.each() is a simple way to do that



                    ES 5






                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , function(key , value)
                    setTimeout(function()
                    console.log('Time is: '+key+' .. Value is: '+value);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





                    Additional ES 6






                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , (key , value) =>
                    setTimeout(() =>
                    console.log(`Time is: $key .. Value is: $value`);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>








                    share|improve this answer















                    While you tagged a Jquery .. So $.each() is a simple way to do that



                    ES 5






                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , function(key , value)
                    setTimeout(function()
                    console.log('Time is: '+key+' .. Value is: '+value);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





                    Additional ES 6






                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , (key , value) =>
                    setTimeout(() =>
                    console.log(`Time is: $key .. Value is: $value`);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>








                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , function(key , value)
                    setTimeout(function()
                    console.log('Time is: '+key+' .. Value is: '+value);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , function(key , value)
                    setTimeout(function()
                    console.log('Time is: '+key+' .. Value is: '+value);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , (key , value) =>
                    setTimeout(() =>
                    console.log(`Time is: $key .. Value is: $value`);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>





                    var Json = 
                    1000: "Paragraph 1",
                    2000: "Paragraph 2",
                    2500: "Paragraph 3",
                    5000 : "Paragraph 5",
                    11500: "Paragraph 20"
                    ;


                    PrintResults(Json);


                    function PrintResults(result)
                    $.each(result , (key , value) =>
                    setTimeout(() =>
                    console.log(`Time is: $key .. Value is: $value`);
                    , key);
                    );

                    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 7 at 18:11

























                    answered Mar 7 at 17:46









                    Mohamed-YousefMohamed-Yousef

                    19.8k31224




                    19.8k31224





















                        0














                        If you wanted to show the lines using a consistent time difference between each you could use setTimeout's brother function, setInterval.



                        If you want, you could use setInterval and use a function to change the interval time



                        var waitTime = 1000;
                        var myFunction = function()
                        //your code to display a line of text

                        clearInterval(interval);
                        waitTime += 50; //make your changes to wait time
                        interval = setInterval(myFunction, waitTime);

                        var interval = setInterval(myFunction, waitTime);


                        Lastly, you could use the jquery delay function, but this only works if you're using jquery effects to display the text. Read about it here: https://api.jquery.com/delay/



                        Ultimately, these are options that will work, but using setTimeout is the cleanest way to solve your problem.






                        share|improve this answer





























                          0














                          If you wanted to show the lines using a consistent time difference between each you could use setTimeout's brother function, setInterval.



                          If you want, you could use setInterval and use a function to change the interval time



                          var waitTime = 1000;
                          var myFunction = function()
                          //your code to display a line of text

                          clearInterval(interval);
                          waitTime += 50; //make your changes to wait time
                          interval = setInterval(myFunction, waitTime);

                          var interval = setInterval(myFunction, waitTime);


                          Lastly, you could use the jquery delay function, but this only works if you're using jquery effects to display the text. Read about it here: https://api.jquery.com/delay/



                          Ultimately, these are options that will work, but using setTimeout is the cleanest way to solve your problem.






                          share|improve this answer



























                            0












                            0








                            0







                            If you wanted to show the lines using a consistent time difference between each you could use setTimeout's brother function, setInterval.



                            If you want, you could use setInterval and use a function to change the interval time



                            var waitTime = 1000;
                            var myFunction = function()
                            //your code to display a line of text

                            clearInterval(interval);
                            waitTime += 50; //make your changes to wait time
                            interval = setInterval(myFunction, waitTime);

                            var interval = setInterval(myFunction, waitTime);


                            Lastly, you could use the jquery delay function, but this only works if you're using jquery effects to display the text. Read about it here: https://api.jquery.com/delay/



                            Ultimately, these are options that will work, but using setTimeout is the cleanest way to solve your problem.






                            share|improve this answer















                            If you wanted to show the lines using a consistent time difference between each you could use setTimeout's brother function, setInterval.



                            If you want, you could use setInterval and use a function to change the interval time



                            var waitTime = 1000;
                            var myFunction = function()
                            //your code to display a line of text

                            clearInterval(interval);
                            waitTime += 50; //make your changes to wait time
                            interval = setInterval(myFunction, waitTime);

                            var interval = setInterval(myFunction, waitTime);


                            Lastly, you could use the jquery delay function, but this only works if you're using jquery effects to display the text. Read about it here: https://api.jquery.com/delay/



                            Ultimately, these are options that will work, but using setTimeout is the cleanest way to solve your problem.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 7 at 18:52

























                            answered Mar 7 at 17:39









                            yojake42yojake42

                            92




                            92





















                                0














                                It can be done using javascript like this






                                var obj = 
                                1000: "Paragraph 1",
                                2000: "Paragraph 2",
                                2500: "Paragraph 3",
                                11500: "Paragraph 20"


                                function displayResults(obj)

                                var time = Object.keys(obj);
                                var val = Object.values(obj);
                                time.forEach(function(item, index)
                                setTimeout(function()
                                console.log("The time is " + item + " The value is " + val[index]);
                                , item);
                                )



                                displayResults(obj);








                                share|improve this answer























                                • You are creating multiple setTimeouts in this approach.See my answer.

                                  – Charlie H
                                  Mar 8 at 6:24












                                • I understand. Thank you

                                  – Sachintha Nayanajith
                                  Mar 9 at 9:10















                                0














                                It can be done using javascript like this






                                var obj = 
                                1000: "Paragraph 1",
                                2000: "Paragraph 2",
                                2500: "Paragraph 3",
                                11500: "Paragraph 20"


                                function displayResults(obj)

                                var time = Object.keys(obj);
                                var val = Object.values(obj);
                                time.forEach(function(item, index)
                                setTimeout(function()
                                console.log("The time is " + item + " The value is " + val[index]);
                                , item);
                                )



                                displayResults(obj);








                                share|improve this answer























                                • You are creating multiple setTimeouts in this approach.See my answer.

                                  – Charlie H
                                  Mar 8 at 6:24












                                • I understand. Thank you

                                  – Sachintha Nayanajith
                                  Mar 9 at 9:10













                                0












                                0








                                0







                                It can be done using javascript like this






                                var obj = 
                                1000: "Paragraph 1",
                                2000: "Paragraph 2",
                                2500: "Paragraph 3",
                                11500: "Paragraph 20"


                                function displayResults(obj)

                                var time = Object.keys(obj);
                                var val = Object.values(obj);
                                time.forEach(function(item, index)
                                setTimeout(function()
                                console.log("The time is " + item + " The value is " + val[index]);
                                , item);
                                )



                                displayResults(obj);








                                share|improve this answer













                                It can be done using javascript like this






                                var obj = 
                                1000: "Paragraph 1",
                                2000: "Paragraph 2",
                                2500: "Paragraph 3",
                                11500: "Paragraph 20"


                                function displayResults(obj)

                                var time = Object.keys(obj);
                                var val = Object.values(obj);
                                time.forEach(function(item, index)
                                setTimeout(function()
                                console.log("The time is " + item + " The value is " + val[index]);
                                , item);
                                )



                                displayResults(obj);








                                var obj = 
                                1000: "Paragraph 1",
                                2000: "Paragraph 2",
                                2500: "Paragraph 3",
                                11500: "Paragraph 20"


                                function displayResults(obj)

                                var time = Object.keys(obj);
                                var val = Object.values(obj);
                                time.forEach(function(item, index)
                                setTimeout(function()
                                console.log("The time is " + item + " The value is " + val[index]);
                                , item);
                                )



                                displayResults(obj);





                                var obj = 
                                1000: "Paragraph 1",
                                2000: "Paragraph 2",
                                2500: "Paragraph 3",
                                11500: "Paragraph 20"


                                function displayResults(obj)

                                var time = Object.keys(obj);
                                var val = Object.values(obj);
                                time.forEach(function(item, index)
                                setTimeout(function()
                                console.log("The time is " + item + " The value is " + val[index]);
                                , item);
                                )



                                displayResults(obj);






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Mar 7 at 20:35









                                Sachintha NayanajithSachintha Nayanajith

                                643




                                643












                                • You are creating multiple setTimeouts in this approach.See my answer.

                                  – Charlie H
                                  Mar 8 at 6:24












                                • I understand. Thank you

                                  – Sachintha Nayanajith
                                  Mar 9 at 9:10

















                                • You are creating multiple setTimeouts in this approach.See my answer.

                                  – Charlie H
                                  Mar 8 at 6:24












                                • I understand. Thank you

                                  – Sachintha Nayanajith
                                  Mar 9 at 9:10
















                                You are creating multiple setTimeouts in this approach.See my answer.

                                – Charlie H
                                Mar 8 at 6:24






                                You are creating multiple setTimeouts in this approach.See my answer.

                                – Charlie H
                                Mar 8 at 6:24














                                I understand. Thank you

                                – Sachintha Nayanajith
                                Mar 9 at 9:10





                                I understand. Thank you

                                – Sachintha Nayanajith
                                Mar 9 at 9:10

















                                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%2f55049605%2fwhat-is-the-most-efficient-way-of-creating-a-sequence-of-timouts-in-json%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

                                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

                                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