Reputation: 8519
I have an custom object declared (ThreadObj) and I want to create a THREADLISTS, holding multiple arrays of Threadlist. So
Threadlist:ThreadObj[]=[];
THREADLISTS:[ThreadObj[]][ThreadObj]=[][]; //how to type and init?
The first dim is of ThreadObj[] and the second is of ThreadObj.
Cheers
Upvotes: 5
Views: 14009
Reputation: 1
For multi-dimensional array in typescript, you can simply declare and define the variable as
let multiArr:(string|number)[][] = [["Ram","Shyam",1,2,3,"Hari"]];
Upvotes: 0
Reputation: 276199
Example :
type ThreadObj = {foo:string}
type ThreadList = ThreadObj[];
type ThreadListList = ThreadList[];
const obj: ThreadObj = {
foo: '123'
}
const singleDim: ThreadList = [
obj
]
const multiDim: ThreadListList = [
singleDim,
singleDim
]
All in one step:
const allInOneStep: {foo:string}[][] = [
[
{
foo: 'hello'
},
{
foo: 'is it me'
}
],
[
{
foo: 'you are looking for'
}
]
]
Upvotes: 3