본문 바로가기
웹코딩 배우기/· JavaScript

forEach() - 요소를 한 번씩만 호출

by 닐기 2022. 3. 1.

See the Pen forEach() by nilgi (@nilgi) on CodePen.

 

• forEach() 인수 value, index, array 사용

ngs.forEach(myFunction);
  document.getElementById("fe1").innerHTML = ngtxt;
  function myFunction(value, index, array) {
    ngtxt += value + "</br>";
  }

• forEach() 인수 중 value만 사용하면 됨요
  ngs2.forEach(myFunction);
  document.getElementById("fe2").innerHTML = ngtxt2;
  function myFunction(value) {
    ngtxt2 += value + "</br>";
  }