var data = [1, 2, 3, 4, 5, 6];
// traditional for loopfor(let i=0; i<=data.length; i++) {
console.log(data[i]) // 1 2 3 4 5 6
}
// using for...offor(let i of data) {
console.log(i) // 1 2 3 4 5 6
}
// using for...infor(let i in data) {
console.log(i) // Prints indices for array elements
console.log(data[i]) // 1 2 3 4 5 6
}
// using forEach
data.forEach((i) => {
console.log(i) // 1 2 3 4 5 6
})
// NOTE -> forEach method is about 95% slower than the traditional for loop// using map
data.map((i) => {
console.log(i) // 1 2 3 4 5 6
})
Posted by: Guest
on December-18-2020
0
loop array
dataType[] arrayRefVar; // preferred way.or
dataType arrayRefVar[]; // works but not preferred way.
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems
resetting your password contact us
Check Your Email and Click on the link sent to your email