Answers for "how to use for each"

35

for each js

const fruits = ['mango', 'papaya', 'pineapple', 'apple'];

// Iterate over fruits below

// Normal way
fruits.forEach(function(fruit){
  console.log('I want to eat a ' + fruit)
});
Posted by: Guest on March-29-2020
23

foreach jas

const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));
Posted by: Guest on January-10-2020
20

javascript for each loop

var colors = ["red", "blue", "green"];
colors.forEach(function(color) {
    console.log(color);
});
Posted by: Guest on July-19-2019
10

enhanced for loop java

class AssignmentOperator {
   public static void main(String[] args) {
      
      char[] vowels = {'a', 'e', 'i', 'o', 'u'};
      // foreach loop
      for (char item: vowels) {
         System.out.println(item);
      }
   }
}
Posted by: Guest on March-04-2020
3

for each

const array1 = ['a', 'b', 'c'];

array1.forEach(element => console.log(element));

// expected output: "a"
// expected output: "b"
// expected output: "c"
Posted by: Guest on April-08-2020
1

for each java

public class JavaArray {

    public static void main(String[] s) {
        int[] age = new int[5];
        age[0] = 21;
        age[1] = 23;
        age[2] = 45;
        age[3] = 31;
        age[4] = 33;
        for (int a : age) {
            System.out.println("age= " + a);
        }

    }
}
Posted by: Guest on November-24-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language