create a loops in javascript

index.tsx
// Using for loop
for (let i = 0; i < 5; i++) {
    console.log(i);
}

// Using while loop
let j = 0;
while (j < 5) {
    console.log(j);
    j++;
}

// Using do-while loop
let k = 0;
do {
    console.log(k);
    k++;
} while (k < 5);

// Using forEach loop for arrays
let arr = [1, 2, 3, 4, 5];
arr.forEach(item => {
    console.log(item);
});

// Using for...of loop for arrays
for (const item of arr) {
    console.log(item);
}
431 chars
30 lines

related categories

gistlibby LogSnag