Answered by : sjdev
var nums = [1, 2, 3, 5];
for (var i = 0; i,nums.length; i++){ console.log(nums[i]);
}
Source : | Last Update : Wed, 06 Jan 21
Answered by : stormy-skylark-e7f0rpz3ug2f
for (var i = 0; i < 4; i++) {
}
Source : https://web.roblox.com/users/390311109/profile | Last Update : Sun, 18 Jul 21
Answered by : misty-manatee-jksm3ry6yp5h
var sum = 0;
for (var i = 0; i < a.length; i++) {
sum + = a[i];
} // parsing an array
Source : https://htmlcheatsheet.com/js/ | Last Update : Thu, 18 Nov 21
Answered by : michael-futral
//pass an array of numbers into a function and log each number to the console
function yourFunctionsName(arrayToLoop){ //Initialize 'i' as your counter set to 0 //Keep looping while your counter 'i' is less than your arrays length //After each loop the counter 'i' is to increased by 1 for(let i = 0; i <arrayToLoop.length; i++){ //during each loop we will console.log the current array's element //we use 'i' to designate the current element's index in the array console.log(arrayToLoop[i]) }
}
//Function call below to pass in example array of numbers
yourFunctionsName([1, 2, 3, 4, 5, 6])
Source : | Last Update : Thu, 05 May 22
Answered by : energetic-echidna-zpf7lsuouyos
for (i in things) { // If things is an array, i will usually contain the array keys *not advised* // If things is an object, i will contain the member names // Either way, access values using: things[i]
}
Source : https://stackoverflow.com/questions/52080/how-do-i-build-a-loop-in-javascript | Last Update : Tue, 22 Feb 22
Answered by : determined-dolphin-y3ad1uh0jfe5
for (let i=0; i<10; i++) { console.log(i)
}
Source : https://www.youtube.com/watch?v=dxc4Etdou6k | Last Update : Wed, 24 Nov 21
Answered by : ankur-prajapati
For printing 0 to 9
you can write like below also
var i;
for (i = 0; i < 10; i++) { console.log(i);
}
Source : | Last Update : Sat, 27 Feb 21
Answered by : vikas
var i;
for (i = 0; i < 10 ; i++) { //do something
}
Source : | Last Update : Thu, 06 Aug 20
Answered by : nutty-newt-794lh8j2t45y
var listItem = [ {name: 'myName1', gender: 'male'}, {name: 'myName2', gender: 'female'}, {name: 'myName3', gender: 'male'}, {name: 'myName4', gender: 'female'}, ] for (const iterator of listItem) { console.log(iterator.name+ ' and '+ iterator.gender); }
Source : | Last Update : Sat, 16 May 20
Answered by : naly-moslih
for (let i = 0, len = cars.length, text = ""; i < len; i++) { text += cars[i] + "<br>";
}
Source : | Last Update : Sun, 29 May 22