Search code examples
angularangularjs-directiveangularjs-scope

how to store string value pairs in array format in angular 6


I am getting responses like:

Do you Have Multiple locations?,yes,How many Physical locations?,4

The required format is:

[Do you Have Multiple locations?,yes],[How many Physical locations?,4],....

Can anyone recommend any suggestion?


Solution

  • You can create a class like,

    export class MyClass{
        question: string;
        answer: string;
    }
    

    and then create an array of the above object as,

    myList : MyClass[] = [];

    push the object to this array by,

    this.myList.push(yourObject);