我有一个包含行数组的矩阵。
let matrix=[['hello'],['world']];
我正在复制行。
matrix=matrix.map(x=>String(x).repeat(2)).map(x=>x.match(new RegExp??))
我想要得到
[['hello','hello'],['world','world']]
最佳答案
如果你想复制数组,可以使用concat
const matrix = [
['hello'],
['world']
];
const res = matrix.map(a => a.concat(a))
console.log(res);
或者假设您有一个数组数组,并且您想要获取 N 个条目而不是 1 个:
const matrix = [
['hello'],
['world']
];
const res = matrix.map(a => Array(4).fill(...a));
console.log(res);
关于javascript - 如何使用 match() 分割数组中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77005871/