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)
});
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)
});
js for each item do
let array = ['Item 1', 'Item 2', 'Item 3'];
array.forEach(item => {
console.log(item); // Logs each 'Item #'
});
for each functions javascript
//Am goinmg to practice the next big thing, using for.each function yo tripple iontegers in an array :)
//for.each function is used to run a command on each number or string in an array
const theFigures = [2,4,5,6,7,8,9,12,23,45,68,31,90];
const afterMath = (num) => {
const theArray = [];
num.forEach((n) => {
const trippled = n*3;
theArray.push(trippled);
});
return theArray;
}
console.log(afterMath(theFigures));
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us