0. 質問の順番が固定のプログラム

以下のように入力してください。

// Text/Instructions
this.options.items.push({
          "type": "text",
           "title": "調査",
           "content": "以下の質問項目をよく読み,あなたに当てはまる選択肢をすべて選んでください。"
        })
// Check all that apply
const items = [
  '飼っているのは?', 
  '写真集を持っているのは?', 
  '大好きなのは?', 
  '見たことがあるのは?'
];

for(let i = 0; i < items.length; i++){
  itemNO = i + 1;
  this.options.items.push({
          "required": false,
          "type": "checkbox",
          "options": [
            {
              "label": "犬",
              "coding": "1"
            },
            {
              "label": "猫",
              "coding": "2"
            },
            {
              "label": "鳥",
              "coding": "3"
            },
            {
              "label": "兎",
              "coding": "4"
            },
            {
              "label": "亀",
              "coding": "5"
            }
          ],
          "label": itemNO +". "+ items[i],
          "name": "Q"+itemNO,
          "shuffle": false
        })
}

1. 連想配列に質問と番号を格納する

質問の順番をランダムにした場合でもデータでは,質問と番号の対応が変わらないようにします。

以下のようにオブジェクト(連想配列)として質問と番号を格納します。

後で使用する場合は,「itemsArray[i].label」や「itemsArray[i].name」で指定します。

データの型:配列・オブジェクト

// Text/Instructions
this.options.items.push({
          "type": "text",
           "title": "調査",
           "content": "以下の質問項目をよく読み,あなたに当てはまる選択肢をすべて選んでください。"
        })
// Check all that apply
const items = [
  '飼っているのは?', 
  '写真集を持っているのは?', 
  '大好きなのは?', 
  '見たことがあるのは?'
];

//各項目と尺度名を配列に格納
var itemsArray = [];
var itemNO;

for(let i = 0; i < items.length; i++){
  itemNO = i + 1;
  itemsArray.push(
    {
      "label": items[i],
      "name": "Q"+itemNO
    }
  )
}

2. 連想配列をシャッフルする

連想配列の順番をシャッフルする場合は,「this.random.shuffle」を使います。

配列シャッフル:「random.shuffle」

//ランダム順にする場合に並び替え
itemsArray = this.random.shuffle(itemsArray)

3. シャッフルされた配列の内容を表示する

以下のように,「for文」の中で連想配列の値を表示します。