Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@kirke

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

More than 1 year has passed since last update.

環境: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
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kirke

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
0
Help us understand the problem. What is going on with this article?