Using Loops With Arrays in JavaScript

let num = [3, 54, 1, 2, 4]

// for(let i=0; i<num.length;i++){
// console.log(num[i])
// }

// For each loop
num.forEach((element)=>{
console.log(element*element)
})

// Array.from => Use to create an array from any other object
// Array.from ("Sage")
let name = "Siddharth Kanojiya"
let arr = Array.from(name)
console.log(arr)

// Array...for => For of loop can be used to get the value from an array
for (let i of num){
console.log(i)
}

// Array...in for in loop can be used to get the key from an array

for(let i in num){
console.log(num[i])
}

Thank you for reading this. If you like this article, please give it a thumbs up and share it. Also, feel free to leave comments below

https://www.buymeacoffee.com/junoriver88

3
Subscribe to my newsletter

Read articles from Siddharth Kanojiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Siddharth Kanojiya
Siddharth Kanojiya

I am very passionate Coder https://www.buymeacoffee.com/junoriver88