How to create a string from one row of a two-dimensional character array in TypeScript

1 Answer

0 votes
// Create and initialize the 2D array
const charArray2D = [
    ['T', 'y', 'p', 'e', 'S', 'c', 'r', 'i', 'p', 't'],
    ['p', 'r', 'o', 'g', 'r', 'a', 'm', 'm', 'i', 'n', 'g'],
    ['l', 'a', 'n', 'g', 'u', 'a', 'g', 'e']
];

// row 1 (second row)
const rowIndex = 1;
const selectedRow = charArray2D[rowIndex];

// Convert the row to a string
const s = selectedRow.join('');

console.log(s);



/*
run:

"programming" 

*/

 



answered Feb 8, 2025 by avibootz
...