Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

javascript loop through array

var colors = ["red","blue","green"];
colors.forEach(function(color) {
  console.log(color);
});
Comment

javascript loop through array

let array = ['Item 1', 'Item 2', 'Item 3'];

for (let item of array) {
  console.log(item);
}
Comment

javascript loop through array

const myArray = ['foo', 'bar'];

myArray.forEach(x => console.log(x));

//or

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

How to Loop Through an Array with a for…in Loop in JavaScript

const scores = [22, 54, 76, 92, 43, 33];

for (i in scores) {
    console.log(scores[i]);
}

// will return
// 22
// 54
// 76
// 92
// 43
// 33
Comment

javascript loop through array

const numbers = [1, 2, 3, 4]
numbers.forEach(number => {
	console.log(number);
}

for (let i = 0; i < number.length; i++) {
	console.log(numbers[i]);
}
Comment

javascript loop through array

const array = ["one", "two", "three"]
array.forEach(function (item, index) {
  console.log(item, index);
});
 Run code snippet
Comment

javascript function loop through array

//function arrayLooper will loop through the planets array
const planets = ["Mercury", "Venus", "Earth", "Mars"];

const arrayLooper = (array) => {
  for (let i = 0; i < array.length; i++) {
    console.log(array[i]);
  }
};
arrayLooper(planets);
Comment

loop through array javascript

/* ES6 */
const cities = ["Chicago", "New York", "Los Angeles"];
cities.map(city => {
	console.log(city)
})
Comment

loop through array in javascript

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
}
Comment

js looping through array

let Hello = ['Hi', 'Hello', 'Hey'];

for(let i = 0; i < Hello.length; i++) {
    console.log(Hello[i]); // -> Hi Hello Hey
}
Comment

loop through an array in js

let exampleArray = [1,2,3,4,5]; // The array to be looped over

// Using a for loop
for(let i = 0; i < exampleArray.length; i++) {
    console.log(exampleArray[i]); // 1 2 3 4 5
}
Comment

Iterate Through an Array with a For Loop

var arr = [10, 9, 8, 7, 6];
for (var i = 0; i < arr.length; i++) {
   console.log(arr[i]);
}
Comment

how to loop through an array

int[] numbers = {1,2,3,4,5};
for (int i = 0; i < numbers.length; i++) {
	System.out.println(i);
}
Comment

javascript loop through array

array.forEach(item => console.log(item));
Comment

javascript loop through array

var numbers = [1, 2, 3, 4, 5];
numbers.forEach((Element) => console.log(Element));
Comment

iterate through an array

var arr = [1,2,3,4,5,6,7,8];

// Uses the usual "for" loop to iterate
for(var i= 0, l = arr.length; i< l; i++){
	console.log(arr[i]);
}

console.log("========================");

//Uses forEach to iterate
arr.forEach(function(item,index){
	console.log(item);
});
Comment

loop over an array

let fruits = ['Apple', 'Banana'];

fruits.forEach(function(item, index, array) {
  console.log(item, index);
});
// Apple 0
// Banana 1
Comment

javascript loop through array

let data = [1,2,3];

data.forEach(n => console.log(n));
Comment

javascript loop through array

const array = [1, 2, 3, 4];

for(num of array) {
  console.log(num); 
}
Comment

javascript best way to loop through array

var len = arr.length;
while (len--) {
    // blah blah
}
Comment

how to loop over an array in js

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

// Using for each loop
data.forEach( (x) => {
  console.log(x)
}
Comment

Javascript using for loop to loop through an array

// Durations are in minutes 
const tasks = [
  {
    'name'     : 'Write for Envato Tuts+',
    'duration' : 120
  },
  {
    'name'     : 'Work out',
    'duration' : 60
  },
  {
    'name'     : 'Procrastinate on Duolingo',
    'duration' : 240
  }
];

const task_names = [];
 
for (let i = 0, max = tasks.length; i < max; i += 1) {
    task_names.push(tasks[i].name);
}

console.log(task_names) // [ 'Write for Envato Tuts+', 'Work out', 'Procrastinate on Duolingo' ]
Comment

javascript loop through array

var myStringArray = ["Hello","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
    console.log(myStringArray[i]);aegweg
    //Do something
}
Comment

javascript loop through array

/*Testing*/
let con = 6;
Comment

Loop through array

String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
System.out.println(cars[0]);

// Change elements in array
cars[0] = "Opel";
System.out.println(cars[0]);

// Length of array
System.out.println(cars.length);

// Loop through array
for (int i = 0; i < cars.length; i++) {
  System.out.println(cars[i]);
}
Comment

javascript loop through array

var myStringArray = ["Hello","World"];
var arrayLength = myStringArray.length;
for (var i = 0; i < arrayLength; i++) {
    console.log(myStringArray[i]);
    //Do something
}
 Run code snippet
Comment

Loop through an array

String[] fruits = {"apple", "orange", "pear"};
for(int i=0; i<fruits.length; i++)
{
System.out.println(fruits[i]);

}
Comment

loop through an array

String[] myStringArray = {"Hello", "World"};
for (String s : myStringArray) {
    // Do something
}
Comment

Iterating or loop through the elements of an array is with a for loop (for):

var keys = Object.keys(o);   // Get an array of property names for object o
var values = []              // Store matching property values in this array
for(var i = 0; i < keys.length; i++) {  // For each index in the array
    var key = keys[i];                  // Get the key at that index
    values[i] = o[key];                 // Store the value in the values array
}
Comment

loop over an array

fruits.forEach(function(item, index, array) {
  console.log(item, index)
})
// Apple 0
// Banana 1
Comment

How to Loop through Array Elements

for str in ${myArray[@]}; do
  echo $str
done
Comment

javascript loop through array

for(int counter=myArray.length - 1; counter >= 0;counter--){
            System.out.println(myArray[counter]);
        }
Comment

loop through array

#include <iostream>
using namespace std;

int main ()
{
   string texts[] = {"Apple", "Banana", "Orange"};
   for( unsigned int a = 0; a < sizeof(texts); a = a + 1 )
   {
       cout << "value of a: " << texts[a] << endl;
   }

   return 0;
}
Comment

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

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
}
Comment

How to Loop Through an Array with a for…of Loop in JavaScript

const scores = [22, 54, 76, 92, 43, 33];

for (score of scores) {
    console.log(score);
}

// will return
// 22
// 54
// 76
// 92
// 43
// 33
Comment

How to Loop Through an Array with a for Loop in JavaScript

const scores = [22, 54, 76, 92, 43, 33];

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

// will return
// 22
// 54
// 76
// 92
// 43
// 33
Comment

javascript looping through array

javascript loop through array
Comment

iterate over array of html elements

const imgs = document.querySelectorAll(".img");
    // You can't simply use imgs.forEach as it is not exactly an array. To fix that, first convert it to an array and then iterate.
	[...imgs].forEach(img => {
			console.log(img);
	});
Comment

javascript loop through array

/* ricky */
Comment

PREVIOUS NEXT
Code Example
Shell :: autosaving in VIM 
Shell :: cairo dock/glx dock install on ubuntu 22. 
Shell :: ls show uid gid 
Shell :: exporting samtools to path 1.13 
Shell :: linux pdf page thumbnail 
Shell :: uninstall nvim arch 
Shell :: disable windows 11 tpm secureboot cpu ram storage check 
Shell :: micronucleus: error while loading shared libraries: libusb-0.1.so.4: cannot open shared object file: No such file or directory 
Shell :: linux short prompt 
Shell :: Comparing float or integers in if using bash 
Shell :: delete the branch with the old name on the remote repository 
Shell :: How do I check my graphics card size in Linux? 
Shell :: command to ceck number of lines or words in a file 
Shell :: linux bash script skip first parameter 
Shell :: linode aapanel info location 
Shell :: tiger vnc faster 
Shell :: grep contains two strings 
Shell :: gitattributes -diff 
Shell :: Docker linuxmint how to 
Shell :: fish function to change php version .env 
Shell :: ssh no host key files found 
Shell :: install codium Fedora 
Shell :: cd to a sub-directory 
Shell :: PortableVisibilityConverter 
Shell :: wsl networking 
Shell :: docker pull 
Shell :: edit git commits 
Shell :: post clone remove line in file 
Shell :: turbo top for linux 
Shell :: keycloak constraint already exists 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =