// 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}
let array =[1,2,3,4];//Your arrayfor(let element of array ){//Now element takes the value of each of the elements of the array//Do your stuff, for example...console.log(element);}
let arr =['js','python','c++','dart']// no 1for(item of arr){console.log(item);}// no 2for(var item =0; item < arr.length; item++){console.log(arr[i]);}// no 3
arr.forEach(item=>{console.log(item);})// no 4
arr.map(item=>{console.log(item);})// no 5var item =0;while(item < arr.length){console.log(arr[item]);
item++;}
array =[1,2,3,4,5,6];//set variable//set the stop count // increment each loopfor(let i =0; i < array.length;i++){
array[i]//iterate through each index.//add the intructions you would like to perform.// add any method to array[}
var arr =[1,2,3,4,5,6,7,8];// Uses the usual "for" loop to iteratefor(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);});
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}
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;}