[ES6] for of文で配列要素の値を取得

2021年10月13日

書式
for(const 変数名 of 配列名)

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<script>
const intArr = [11, 22, 10];
const strArr = ["study", "skill", "arkgame"];
//int配列  for of処理
for(const val of intArr) {
alert(val);
}
//string配列 for of処理
for(const val of strArr) {
alert(val);
}
</script>
<script> const intArr = [11, 22, 10]; const strArr = ["study", "skill", "arkgame"]; //int配列  for of処理 for(const val of intArr) { alert(val); } //string配列 for of処理 for(const val of strArr) { alert(val); } </script>
<script>
const intArr = [11, 22, 10];
const strArr = ["study", "skill",  "arkgame"];

//int配列  for of処理
for(const val of intArr) {
  alert(val);
}

//string配列 for of処理
for(const val of strArr) {
  alert(val);
}
</script>

結果
11
22
10
study
skill
arkgame

ECMAScript/ES6

Posted by arkgame