Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

코딩공주

array 형태의 데이터를 li에 넣어서 list화 하기 본문

코딩정보

array 형태의 데이터를 li에 넣어서 list화 하기

소수소수 2019. 2. 27. 11:57

https://stackoverflow.com/questions/39277978/javascript-li-list-from-array-with-for-loop




var array = [1, 2, 3, "mm", "b", "c", "mm", "y", "mm"];
var list = document.getElementById("list");

function addText(array) {
  for (var i = 0; i < array.length; i++) {
    var text = array[i];
    if (text == "mm") {
      var listItem = document.createElement("LI");
      listItem.textContent = text;
      list.appendChild(listItem);
    }
  }
}

addText(array);
<ul id="list">
</ul>


array 형태의 데이터를 특정 html태그를 추가해서 데이터 넣기


밑줄 핵심 힌트

Comments