“JavaScript Foreach” Kod odpowiedzi

JavaScript Foreach

const avengers = ['thor', 'captain america', 'hulk'];
avengers.forEach((item, index)=>{
	console.log(index, item)
})
connect.sonveer

JavaScript Foreach

var colors = ['red', 'blue', 'green'];

colors.forEach(function(color) {
  console.log(color);
});
Grepper

JavaScript Foreach

const products = [
    { name: 'Laptop', price: 32000, brand: 'Lenovo', color: 'Silver' },
    { name: 'Phone', price: 700, brand: 'Iphone', color: 'Golden' },
    { name: 'Watch', price: 3000, brand: 'Casio', color: 'Yellow' },
    { name: 'Aunglass', price: 300, brand: 'Ribon', color: 'Blue' },
    { name: 'Camera', price: 9000, brand: 'Lenovo', color: 'Gray' },
];
products.forEach(product => console.log(product.name));
//Output: Laptop Phone Watch Aunglass Camera
Ariful Islam Adil(Code Lover)

JavaScript Foreach

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

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

JavaScript Foreach

let numbers = ['one', 'two', 'three', 'four'];

numbers.forEach((num) => {
  console.log(num);
});  // one   //two //three // four
Batman

JavaScript Foreach

fruits.forEach(function(item, index, array) {
  console.log(item, index)
})
// Apple 0
// Banana 1
Jittery Jay

JavaScript Foreach

const colors = ['blue', 'green', 'white'];

function iterate(item) {
  console.log(item);
}

colors.forEach(iterate);
// logs "blue"
// logs "green"
// logs "white"
Dangerous Dogfish

JavaScript Foreach

// Arrow function
forEach((element) => { /* ... */ })
forEach((element, index) => { /* ... */ })
forEach((element, index, array) => { /* ... */ })
sheikh mohd afiq ahlami mohd noor

JavaScript Foreach

const Gpio = require('../onoff').Gpio;
const led = new Gpio(17, 'out');
Clever Cardinal

Odpowiedzi podobne do “JavaScript Foreach”

Pytania podobne do “JavaScript Foreach”

Więcej pokrewnych odpowiedzi na “JavaScript Foreach” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu