Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 对数组进行角度重新格式化_Arrays_Angular - Fatal编程技术网

Arrays 对数组进行角度重新格式化

Arrays 对数组进行角度重新格式化,arrays,angular,Arrays,Angular,我有一个如下所示的数组:[] 这是我的代码: this.old = this.checFilter.map(r=>r.userId); this.checked.push(this.old); console.log(this.checked); 如您所见,我在第一个数组中有5个数组。然后我把它推到另一个阵列。结果是推送后显示2个阵列。但是我需要一个包含6个条目的数组。您必须使用concat函数: 使用以下命令: 这会将每个值直接推送到数组中,而不是将整个数组作为一个值,但要小心。这种

我有一个如下所示的数组:[]

这是我的代码:

this.old = this.checFilter.map(r=>r.userId);
this.checked.push(this.old);
console.log(this.checked);

如您所见,我在第一个数组中有5个数组。然后我把它推到另一个阵列。结果是推送后显示2个阵列。但是我需要一个包含6个条目的数组。

您必须使用concat函数:

使用以下命令:

这会将每个值直接推送到数组中,而不是将整个数组作为一个值,但要小心。这种方法会使数组发生变异

this.checFilter.map(r => this.checked.push(r.userId));
请尝试使用以下方法平整阵列:

arr.flatMap(f=> f);
例如:

让arr=[
['pfQ1A3M0S1V6icGcLKTIdBoIWA42',
'0RRFZUW6RACSXOAKNCJ6GGGB9Y1',
‘6RXWFEsEMdZWJTeUN3wMAj1PzYu2’,
“QK39c753XUP7MbqVbMObSYPdmKB2”,
“R8SN2EYTBTSVSVUNQ71NXAGBO2”,],
“XG9oznIXpucqPFekDrGm6ixpctt2”
]
const result=arr.flatMap(f=>f);

控制台日志(结果)请以文本而不是图像的形式提供变量。您将新值推到错误的级别…第一个数组中没有5个数组。您有一个包含5个元素的数组。我假设您想要数组中的6个元素?您可以使用
concat
请在回答中添加一些解释,以便其他人也可以学习。
this.checFilter.map(r => this.checked.push(r.userId));
arr.flatMap(f=> f);