I have strings like this :
... and so on.
I need to format the strings and produce arrays in array like this :
E.g.:
var myArray = [
[831,403],
[746,399],
[745,409],
[752,426],
[764,435],
[775,448],
[781,467],
[780,483],
[776,509],
[826,513],
];
It is possible and how? Thanks in advance!
function parseToMatrix(str, rowCount = 2) {
let numbers_array = str.split(",").map((str) => parseFloat(str));
let matrix = [];
for (let i = 0; i < numbers_array.length; i += rowCount) {
matrix.push(numbers_array.slice(i, i + rowCount));
}
return matrix;
}
let str =
"831,403,746,399,745,409,752,426,764,435,775,448,781,467,780,483,776,509,826,513";
console.log(parseToMatrix(str));