Answers for "foreach javascript ecma6"

1

loop through arrays in es6

var sandwiches = [
	'tuna',
	'ham',
	'turkey',
	'pb&j'
];

sandwiches.forEach(function (sandwich, index) {
	console.log(index);
	console.log(sandwich);
});

// returns 0, "tuna", 1, "ham", 2, "turkey", 3, "pb&j"
Posted by: Guest on April-23-2020
2

es6 forEach

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

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

// expected output: "a"
// expected output: "b"
// expected output: "c"
Posted by: Guest on August-25-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language