'Need to create a way to assign values into an array using Typescript

this is my array ,

var alphas:string[]; 
alphas = ['abc1','abc2','abc3']  --> (this array will be change)

my modal class is ,

export class Team {
  TeamName: string;
}

And , I have to assign above alphs value into TeamName. I do it like way ,

      let selectedTeams = [];
      for(let i = 0; i < alphas.length ; i++){
        let team: Team = new Team();
        team.TeamName = alphas[i];
        selectedTeams.push(team);
      }

then I need to call this method like way,

this.selectedReferredTo = [ selectedTeams[1] ,selectedTeams[2] , selectedTeams[3] ];

In here I'm stuck? can you help me to call above method in different array sizes?



Solution 1:[1]

You can try using destructuring assignment.

at the final step your code will look like

this.selectedReferredTo = [ ...selectedTeams ];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AntGrisha