将多个字符串标签和数组保存到打字稿中的关联数组

saving multiple string labels and array to associated array in typescript

我正在构建一个 ionic 4 应用程序,它必须将多个标签和数组保存到关联数组,但在初始化和推送新项目到数组以及关联数组中 editing/updating 现有数组项目时遇到问题。

  array1 = {
           'Question1'=>['True','True'],
           'Question2'=>['False, False'] 
           }

我如何在打字稿中做到这一点?

JavaScript/TypeScript 不支持具有命名索引的数组,数组始终使用编号索引。但是,您可以使用一个简单的对象来执行此操作,例如:

    const questions = {
        "question1": [true, true],
        "question2": [false, false]
    }
    
    console.log(questions);
    console.log(questions["question1"]) // prints [true, true]