在多维对象数组中推送值-打字稿

时间:2020-09-15 14:00:20

标签: javascript typescript

我有一个动态的多维对象数组,我想在内部数组中推送新值,如下例所示。

columnType: any[][] = [
        [
            { Id: '1', Name: 'First Name' },
            { Id: '2', Name: 'Last Name' },
            { Id: '3', Name: 'Email' }
        ],
        [
            { Id: '1', Name: 'First Name' },
            { Id: '2', Name: 'Last Name' },
            { Id: '3', Name: 'Email' }
        ],
        [
            { Id: '1', Name: 'First Name' },
            { Id: '2', Name: 'Last Name' },
            { Id: '3', Name: 'Email' }
        ]
     ]

我需要按照以下示例中的要求将元素推入内部数组

[
    [
        { Id: '1', Name: 'First Name' },
        { Id: '2', Name: 'Last Name' },
        { Id: '3', Name: 'Email' },
        { Id: '4', Name: 'Voice Phone' }
    ],
    [
        { Id: '1', Name: 'First Name' },
        { Id: '2', Name: 'Last Name' },
        { Id: '3', Name: 'Email' },
        { Id: '4', Name: 'Voice Phone' }
    ],
    [
        { Id: '1', Name: 'First Name' },
        { Id: '2', Name: 'Last Name' },
        { Id: '3', Name: 'Email' },
        { Id: '4', Name: 'Voice Phone' }
    ]
 ]

我尝试过的代码

let val={ Id: '4', Name: 'Voice Phone' };
for(var i=0;i<this.columnType.length;i++){
      for(var j=0;j<this.columnType[i].length;j++){
        this.columnType[i][j].push(val);
      }
    }

0 个答案:

没有答案