Answers for "loop array with array"

32

javascript loop through array

var data = [1, 2, 3, 4, 5, 6];

// traditional for loop
for(let i=0; i<=data.length; i++) {
  console.log(data[i])  // 1 2 3 4 5 6
}

// using for...of
for(let i of data) {
	console.log(i) // 1 2 3 4 5 6
}

// using for...in
for(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
-1

ex:javascript loop array

Help us test exciting upcoming updates in this place! Make sure to report issues and ideas through the Feedback Submission button (right next to the settings button)!
https://www.roblox.com/games/918612434/Test-Sever
The is the Adopt Me test server. It will shutdown spontaneously and frequently as we test. Your data will not load or save here.
Posted by: Guest on May-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language