You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在TypeScript中创建包含指定对象数组的二维数组?

Combine Your Arrays into a 2D Array

Got it! Creating a 2D array that holds your appChartData and versionChartData is really straightforward—you just need to wrap both existing arrays inside another array. Here's how to do it cleanly in TypeScript, including optional type safety for clarity:

If you want explicit type annotations to avoid type confusion later, you can define the structure of your 2D array first:

type CombinedChartData = [
  Array<{date: string, total: number, some_usage: number}>,
  Array<{date: string, ver1sion: number, version2: number}>
];

Step 2: Build the 2D Array

Now simply assign your two arrays to form the 2D structure:

// Assuming your arrays are already populated with data
const combined2DArray: CombinedChartData = [appChartData, versionChartData];

Shorter Alternative (No Explicit Type)

If you don't need the strict type definition, you can do this in one quick line:

const combined2DArray = [appChartData, versionChartData];

Now combined2DArray[0] will reference your appChartData set, and combined2DArray[1] will point to versionChartData—perfect for passing both datasets to components or functions that expect a 2D array input!

内容的提问来源于stack exchange,提问作者Kim2018

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:26:11