“dla każdego” Kod odpowiedzi

JavaScript Foreach

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

dla każdego

const arraySparse = [1,3,,7]
let numCallbackRuns = 0

arraySparse.forEach((element) => {
  console.log(element)
  numCallbackRuns++
})

console.log("numCallbackRuns: ", numCallbackRuns)

// 1
// 3
// 7
// numCallbackRuns: 3
// comment: as you can see the missing value between 3 and 7 didn't invoke callback function.
Magnificent Mink

dla każdego

const arr = ['cat', 'dog', 'fish'];
arr.forEach(element => {
  console.log(element);
});
Ankur

dla każdego

array.foreach((item)=>{
				console.log(item);
             });
Gifted Grouse

dla każdego

const { chromium } = require("playwright");
const fs = require("fs");

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage();
  await page.goto("https://danube-webshop.herokuapp.com");
  const content = await page.evaluate(() => {
    let data = [];

    let books = document.querySelectorAll(".preview");
    books.forEach((book) => {
      let title = book.querySelector(".preview-title").innerText;
      let author = book.querySelector(".preview-author").innerText;
      let price = book.querySelector(".preview-price").innerText;
      data.push({
        title,
        author,
        price,
      });
    });
    return data;
  });

  const jsonData = JSON.stringify(content);
  fs.writeFileSync("books.json", jsonData);
  await browser.close();
})();
Allen Chiu

Dla każdego

let data = ["A", "B", "C", "D"];
function process(element)
{
    console.log(element);
}
// With named Function
data.forEach(process);

// With Lambda/anonymous Function
data.forEach((element) => console.log(element));
Carsten Schlegel

Odpowiedzi podobne do “dla każdego”

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

Przeglądaj inne języki kodu