0

For a multidimensional array whose every element has the same type, it's simple to declare: string[][].

However if each array is different, then how should I do?

function create3DArray(arg): // <----???
{ firstArray: string[] = [] 
  secondArray: number[] = [] 
  thirdArray: CustomType[] = [] 
  return [firstArray, secondArray, thirdArray] 
} 

I have looked at typescript multidimensional array with different types but I'm still not sure how to do it.

Ooker
  • 1,969
  • 4
  • 28
  • 58

1 Answers1

1

You are looking for a tuple. Tuple is an array with finite length, in your case, it is three:

function create2DArray(arg):[string[], number[], CustomType[]] {}
wonderflame
  • 6,759
  • 1
  • 1
  • 17