Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6795979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:24:42+00:00 2026-05-26T18:24:42+00:00

var arr = [[1,2,3],[4,5,6],[7,8,9]]; function out(ar){ var interval = setInterval(function(){ for (var i=0; i<ar.length;i++){

  • 0
var arr = [[1,2,3],[4,5,6],[7,8,9]];


function out(ar){

  var interval = setInterval(function(){
    for (var i=0; i<ar.length;i++){

      for (var j=0;j<ar[i].length;j++){

        document.write(ar[i][j]);

      }
    document.write("</br>");
    }
  clearInterval(interval);
  },1000);

}

out(arr);

http://jsbin.com/edanib/edit

This code works, but i would like to make one second delay before outputting every number.
The above code cannot do that. How do i do that in vanilla Javascript?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:24:43+00:00Added an answer on May 26, 2026 at 6:24 pm

    setInterval isn’t guaranteed to get you 1 second spacing because other things might run, but you can get close with the following

    function out(ar) {
      var i = 0, j = 0;
      var interval = setInterval(function(){
        // Start with the next row if the last one was finished.
        if (i < ar.length && j == ar[i].length) {
          ++i; 
          j = 0;
          // Put a line after it.
          document.body.appendChild(document.createElement('br'));
        }
        // Check if we're out of rows.
        if (i >= ar.length) { clearInterval(interval); return; }
    
        // Write out a number.
        document.body.appendChild(document.createTextNode('' + ar[i][j]));
    
        // We're done with the cell that we just wrote.
        ++j;
      }, 1000 /* milliseconds */);
    }
    

    Put the array indices outside the function, so each time the interval fires, it gets the loop state from the last run.

    Also, you can’t use document.write inside an interval handler because calling document.write after the document has closed clobbers the existing document.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

var thumbs = document.getElementsByTagName(img); for (var i=0; i<thumbs.length; i++) { Core.addEventListener(thumbs[i], click, function() {alert(i);});
$(document).ready(function() { $('a.menuitem').click(function() { var arr = 0; var link = $( this ),
I have following javascript class: var ImageGallery = function(arr) { var ImgArr = arr;
I have this code: var ar = [10,7,8,3,4,7,6]; function isin(n,a){ for (var i=0;i<a.length;i++){ if
I've seen this sort function working fine: var arr = [1,5,3,7,8,6,4,3,2,3,3,4,5,56,7,8,8]; console.log(arr.sort( function(a,b) {
I had a bug, it went like this for(var i=0; i<arr.length; i++){ var v
function ArrayAdditionI(arr) { var numbers = arr(); var arraySum = ; for (var i
Hi when I have an array in actionscript var arr : Array = new
I have an array of integers in string form: var arr = new string[]
var y = new w(); var x = y.z; y.z= function() { doOneThing(); x();

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.