Matrix creation using array

Hi I want to create a matrix ‘B’ like given below while I only have an array ‘A’

A=[0 1 2 3 4]

B= [0 1 2 3 4
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8]
For some reason, these few lines are not working

for (var i=0;i<5;i=i+1){
  for (var j=0;j<5;j=j+1){
            B[i][j] = A[j]+i;
        }
        }

Any help or suggestion will be appreciated.
Thanks

how are you defining A and B?

also if B[i] is undefined, you need to define it somewhere before doing the above or it will not work

I have only defined it as
var B = ;
If its not enough, please tell me what else should i do ?

you can’t add an element to something that is undefined.
B[i] is undefined so you can’t do B[i][j] = A[j]+i, so you need to define B[i] before entering the loop