0
I’m doing an exercise where I should extract rows and columns from a string, creating an array.
Input let str = '1 2 3\n4 5 6\n7 8 9'
, I wrote a code that returns: [ '4 5 6' ]
, but I’d like him to return something like: [4, 5, 6]
(not between quotes). How can I do this?
let str = '1 2 3\n4 5 6\n7 8 9'
let arr = str.split('\n');
let rowResult = [];
let rowFinalResult = [];
for(let i = 0; i < arr.length; i++){
rowResult = arr[i];
rowFinalResult.push([rowResult]);
}
console.log(rowFinalResult[1]);
I found your answer very good, simple, practical and well explained. Thank you! Solved my problem
– retr0