Quantcast
Channel: 配列タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 757

JavaScript5,for文,配列,初心者向け

$
0
0

5,配列とfor文をくみあわせる。

const weather = ["晴れ", "曇り", "雨", "雷"]
for (let i = 0; i < weather.length; i++) {
  let li = document.createElement("li");
  li.textContent = i;
  document.getElementById("number").appendChild(li);
  console.log(i);
}

旧 for (let i = 0; i < 10; i++) {
新 for (let i = 0; i < weather.length; i++) {

○○.length
が ["晴れ", "曇り", "雨", “雷”]の中の数だけ勝手にやってくれる


Viewing all articles
Browse latest Browse all 757

Trending Articles