//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])
let arry = {
name: "Rakibul Islam",
class: "Tane",
grup: "A",
roll: 10,
sub: "Arse"
}
//for in loop used to object
for(let i in arry){
console.log(i,arry[i]);
}
/*
for (statement1; statement2; statement3) {
INSERT CODE
statement1 is executed before for loop starts
statement2 is the condition
statement3 is executed after every loop
}
*/
for (i = 0; i < 5; i++) {
console.log(i);
}
let items = ['beef', 'cabbage', 'javascript']; // Defines a list of items
for (let item of items) { // Defines for loop with a variable of 'item'
console.log(item); // Prints the item that is found
}
let arry = {
name: "Rakibul Islam",
class: "Tane",
grup: "A",
roll: 10,
sub: "Arse"
}
//for in loop used to object
for(let i in arry){
console.log(i,arry[i]);
}
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]
}
var car = {"Tesla":"Model 3", "Mercedes":"V-8 Model"};
for(brandName in car){
console.log(brandName);
}
//Tesla
//Mercedes
for(brandName in car){
console.log(car[brandName]);
}
//Model 3
//V-8 Model
const user ={
name:'Shirshak',
age:25,
subscibers:200,
money:'lolno'
}
for(let x in user){
console.log(user[x]) //name,age,subscriber and money(only get key not value)
}
//first type
for(let i; i< number; i++){
//do stuff
//you can break
break
}
//2nd type
const colors = ["red","green","blue","primary colors"]
colors.forEach((color) =>{
//do stuff
//But you can't breack out of the loop
})
//3rd type might not be considered as a loop
colors.map((color) =>{//do stuff
//no bracking})
let list = ["a", "b", "c"];
// for in
for (let i in list) {
// i is index
console.log(i); // "0", "1", "2",
console.log(list[i]); // "a", "b", "c"
}
// for of
for (let i of list) {
// i is value
console.log(i); // "a", "b", "c"
}