/    Sign up×
Community /Pin to ProfileBookmark

setTimeout() on a line of code

“`
var primarySplit = typeText[counter].split(“”);
primarySplit.forEach((element) => {
pickDiv.innerHTML = pickDiv.innerHTML + primarySplit[pos];
pos += increment;
});
“`

Please be advised that pos(initially set to 0), primarySplit, `pickDiv` all are defined or have relevant document object queries, which is not an issue.

The problem is I tried many methods, but I could give time gap of 1second between every next execution of this code through setTimeout() function:
`pickDiv.innerHTML = pickDiv.innerHTML + primarySplit[pos]; `

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@daveyerwinSep 10.2021 — @bossbond#1636788

you should show us the code where you

attempted to use setTimeout

meanwhile ...

``<i>
</i>&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
&lt;pre id=dsply&gt;&lt;/pre&gt;
&lt;script&gt;
"use strict"
var primarySplit = [1,2,3,4,5,"nThat's All !"];
function populateDsply(){
let a=gen.next();
dsply.textContent += a.value? a.value:"";
if(!a.done)setTimeout(populateDsply,1000);
};
function* Gen(arg,i=0){
while(arg[i]){
yield arg[i++] ;
}
}
var gen = Gen(primarySplit);
populateDsply()
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;<i>
</i>
``
×

Success!

Help @bossbond spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...