// This is a way to loop threw a 2 dimensional array.// If the array has even more dimension you have to use recurrsion.constArrays=[["Array 1"],["Array 2"]];Arrays.forEach((array, index)=>{console.log(index);
array.forEach((item, index)=>{console.log(item);});});
//function arrayLooper will loop through the planets arrayconst planets =["Mercury","Venus","Earth","Mars"];constarrayLooper=(array)=>{for(let i =0; i < array.length; i++){console.log(array[i]);}};arrayLooper(planets);
let arbitraryArr =[1,2,3];// below I choose let, but var and const can also be used for(let arbitraryElementName of arbitraryArr){console.log(arbitraryElementName);}
let exampleArray =[1,2,3,4,5];// The array to be looped over// Using a for loopfor(let i =0; i < exampleArray.length; i++){console.log(exampleArray[i]);// 1 2 3 4 5}
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' ]
var myStringArray =["Hello","World"];var arrayLength = myStringArray.length;for(var i =0; i < arrayLength; i++){console.log(myStringArray[i]);aegweg
//Do something}
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 arraySystem.out.println(cars.length);// Loop through arrayfor(int i =0; i < cars.length; i++){System.out.println(cars[i]);}
var myStringArray =["Hello","World"];var arrayLength = myStringArray.length;for(var i =0; i < arrayLength; i++){console.log(myStringArray[i]);//Do something}Run code snippet
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 elementsconsole.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})
#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;}return0;}
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}