0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

javaScript 乱数 配列 For of ループ For ループ を使ったコード

Last updated at Posted at 2020-05-23

#環境:GAS

#目的:

  • 任意の回数配列にランダムな数字(0〜9)を入れ、それを昇順にソートする。
  • 要素ごとにログで出力する
qiita arrayPractice.js
function arrayPractice() {
  let number_list = [];
  const LOOP_COUNT = 20;
  for (let count = 1; count <= LOOP_COUNT; count ++){
    number_list.push(Math.floor(Math.random()*10));
  }
  Logger.log('result for loop' + number_list)  
  let organize_list = number_list.sort()
  // For (element in array){ } の場合、Xは要素番号となります。
  // 上記方法だとLogger.log(array[element])とする必要があります
  for (let number of organize_list){
    Logger.log(number)             
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?