Answers for "for-in loop javascript"

220

for in javascript

var colors=["red","blue","green"];
for (let i = 0; i < colors.length; i++) { 
  console.log(colors[i]);
}
Posted by: Guest on June-17-2019
21

for in loop javascript

var person = {"name":"taylor","age":31};
for (property in person) {
	console.log(property,person[property]);
}
//name taylor
//age 31
Posted by: Guest on January-17-2020
2

for in javascript

let items = ['beef', 'cabbage', 'javascript']; // Defines a list of items
for (let item of items) { // Defines for loop with a variable of 'item'
  console.log(item); // Prints the item that is found
}
Posted by: Guest on October-25-2020
1

for loop in javascript

For printing 0 to 9

you can write like below also
var i;
for (i = 0; i < 10; i++) {
  console.log(i);
}
Posted by: Guest on February-20-2021
3

for in loop javascript

let array = [1,2,3,4,5,6,7,8,9,10]; 
// our array that we will use the for loop on
for (let i = 0; i < array.length; i++) { 
  // this loop will console log the element at array[i] starting at 0
  // and will continue looping for i < array.length 
  console.log(array[i]);
  // after each loop i will increase by 1
}

// this will console log
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10
Posted by: Guest on October-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language