DEV Community

Siddharth Kanojiya
Siddharth Kanojiya

Posted on

Using Loops With Arrays in JavaScript # 16

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])
}

Top comments (0)