S
S
Sergey But2018-11-24 00:16:20
JavaScript
Sergey But, 2018-11-24 00:16:20

Problem with populating a 2D array?

We get the text from the input, split it into an array by 1 element, put it into a two-dimensional array

var matrix=[];
    var key=prompt('enter key').split(''),
        text=input.value.toUpperCase().split(""); //console.log(text);
   // console.log(key); 
        for (var i=0; i<key.length; i++){
            matrix[i]=[];
            for(var j=0; j<input.length; j++){
                matrix[i][j]=text[j];
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2018-11-24
@StockholmSyndrome

for (var j = 0; j < text.length; j++) {
  matrix[i][j] = text[j];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question