Linked Questions
135 questions linked to/from Asynchronous Process inside a javascript for loop
3263
votes
45
answers
490k
views
JavaScript closure inside loops – simple practical example
var funcs = [];
// let's create 3 functions
for (var i = 0; i < 3; i++) {
// and store them in funcs
funcs[i] = function() {
// each should log its value.
console.log("My value:", i);
...
8
votes
2
answers
2k
views
'setTimeOut' calls in JavaScript 'for' loops, why do they fail? [duplicate]
Let me clarify my question. I'm not asking how to make the following code work. I am aware that you can use the let keyword or an iffe that captures its own value of i. I just need clarification on ...
-1
votes
2
answers
5k
views
How to make for loop in JavaScript synchronous [duplicate]
I want to iterate an array in Javascript and one element will take some time to get processed.
I want to till that element is processed, wait for that.
var splittedText = ["Hello", "World", "How", ...
-1
votes
1
answer
1k
views
Pass urls stored in array to window.open in for loop - Javascript [duplicate]
I'm trying to step through an array and pass my urls stored there to the window.open function. This is what I have.
$('a.linked').click(function(e) {
e.preventDefault();
var i;
var urls = ...
0
votes
0
answers
606
views
Node.js: creating bunch of websocket client connections to send a burst of messages? [duplicate]
I have a node websocket (require('ws')) server that i want to test in terms of load (active connections).
Hence I am trying to write a node client app that makes several connections to the server and ...
-1
votes
2
answers
291
views
Node.js - for loop index is update to last value (surprisingly) [duplicate]
For loop in node.js is behaving quite weirdly. code is as below:
for(var i = 0; i < req.body.stages.length; i++){
if (req.body.current_stage == req.body.stages[i].stage_short_desc){
...
0
votes
2
answers
151
views
How am getting this output ? Javascript ES6 [duplicate]
Please find my snippet here,
for (var i=0;i<11;i++) {
setTimeout( () => console.log(i), 10);
}
How it print 11 for 11 times? since i was set < 11?
if i console it without ...
0
votes
0
answers
184
views
How to create multiple WebSocket connections in a loop (JavaScript) [duplicate]
I have created a websocket server using ratchet, and would like to monitor my servers CPU/Ram usage as the number of concurrent connections goes up. I've tried to do this in the dev console with a ...
0
votes
1
answer
100
views
Before completing the loop promise gets resolved [duplicate]
I am using a loop to update data to the server and once the response from the server is received it is updated in my local db.But before completing all the updates in local db the promise gets ...
0
votes
0
answers
79
views
Javascript: How do I ensure something happens only after forEach loop finishes? [duplicate]
I have a table in a database which has a list of bad_wordsand a list of good_words which replace these bad_words in the input string. This is how I'm doing it, the parameter comment is to be tested ...
-2
votes
1
answer
76
views
I'm struggling with changing this loop as asynchronous nodejs [duplicate]
in a loop -
get some data from mysql
insert the data into specific array ( at the index of i)
but as you know, 'i' increases much earlier than I expected.
I know it's a problem with a sync/async ...
0
votes
0
answers
69
views
Execution order in NodeJS [duplicate]
I'm converting a PHP code to NodeJS. I was running a couple MySQL queries, then I would run other ones based on these results. However, it seems like MySQL queries are run in a particular order in ...
0
votes
0
answers
78
views
Why does my for loop go straight to the end? [duplicate]
I am trying to learn javascript basics through an online course. I have a set of functions that work and I want to run them through a for loop 10 times. Here is the code of my for loop:
for (var ...
0
votes
0
answers
62
views
Cannot access variables within a promise [duplicate]
I'm trying to create a JavaScript object (friends_ringsigs), in which the keys are the values of names[i], and the values are the "result" variable created at the execution of the promise. The problem ...
0
votes
0
answers
58
views
How to synchronize then() with for loop [duplicate]
Here is the code i am facing problem
for (var j = 0; j < 3; j++) {
console.log("for loop"+j);
Data.getById(item)
.then(function (data) {
...