Day 13: Learning JavaScript Arrays & For Loops 🚀
Today i learned Javascript arrays and for loops. 1.Arrays An Array is used to multiple values in single variable. let laptops = ["Hp","Dell","Msi","Lenovo"]; console.log(laptops); Each value in an array ha
Today i learned Javascript arrays and for loops.
1.Arrays
An Array is used to multiple values in single variable.
let laptops = ["Hp","Dell","Msi","Lenovo"];
console.log(laptops);
Each value in an array has an index.The index starts from 0.
console.log(laptops[0]);
console.log(laptops[1]);
2.For Loop
I also learned how to use a for loop to repeat a block of code.
for(let i=1;i<=5;i++){
console.log(i);
}
This prints numbers from 1 to 5.
3.Using a for loop with an Array.
for loop can also be used to go through the values in an array.
`
let laptops = ["Hp", "Lenovo", "msi", "dell"];
for (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}`
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.