Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.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
Javascript 如何从两个深度数组中生成单个深度数组深度数组_Javascript_Node.js - Fatal编程技术网

Javascript 如何从两个深度数组中生成单个深度数组深度数组

Javascript 如何从两个深度数组中生成单个深度数组深度数组,javascript,node.js,Javascript,Node.js,我试图从粘贴在底部的函数中获取数组数组。 问题是,当一个数组出现多次时,我无法确定 我想得到的一个例子是: [ [“批次”、“状态”、“gewijzigd门”、“日期”、“变量”], ['34','ready','projectname','12-12-20','jerry'], ['34','ready','projectname','12-12-20','john'], ['34','ready','projectname','12-12-20','empty'], ['34','ready

我试图从粘贴在底部的函数中获取数组数组。 问题是,当一个数组出现多次时,我无法确定

我想得到的一个例子是:

[
[“批次”、“状态”、“gewijzigd门”、“日期”、“变量”],
['34','ready','projectname','12-12-20','jerry'],
['34','ready','projectname','12-12-20','john'],
['34','ready','projectname','12-12-20','empty'],
['34','ready','projectname','12-12-20','empty'],
['34','ready','projectname','12-12-20','empty']
]
但如果它包含biebs属性。然后我遇到了如下所示的问题

[
[“批次”、“状态”、“gewijzigd门”、“日期”、“变量”],
[
['34','ready','projectname','12-12-20','jerry'],
['34','ready','projectname','12-12-20','john']
],
['34','ready','projectname','12-12-20','empty'],
['34','ready','projectname','12-12-20','empty'],
['34','ready','projectname','12-12-20','empty'],
[
['34','ready','projectname','12-12-20','jerry'],
['34','ready','projectname','12-12-20','john']
]
]
我被困在如何解决这个问题或处理这个结果上。flat()还可以将我想要保留的部分展平。 还是我的功能没有以正确的方式建立

代码粘贴在下面

import {CreateUrls, RemoveLastSlash} from '../../utils/Tools';


const List = (file, { bronUrlSplit, migrStatus }) => {

  const batchMigratie = file.map(d => {
    const { urlBron, subSite } = CreateUrls(d.Url, 'est', parseInt(bronUrlSplit))

    if (d.hasOwnProperty('biebs')) {
      const biebs = d.biebs.split(',')

      const test = biebs.map(element => {
        return [d.Batch, migrStatus, d.Titel, RemoveLastSlash(urlBron), RemoveLastSlash(subSite), element ];
      });
      return test
    }

    return [d.Batch, migrStatus, d.Titel, RemoveLastSlash(urlBron), RemoveLastSlash(subSite), 'empty' ];
  })

  batchMigratie.forEach(element => {
    console.log('element', element)
  });

  return [
    ['Batch', 'status', 'gewijzigd door', 'date', 'variable'],
    ...batchMigratie
  ]
}

export default List


只要检查每个数组元素是否包含另一个数组,就可以了。如果是,则将其每个元素推送到结果,否则仅推送到当前元素。比如:

const arr=[
[“批次”、“状态”、“gewijzigd门”、“日期”、“变量”],
[
['34','ready','projectname','12-12-20','jerry'],
['34','ready','projectname','12-12-20','john']
],
['34','ready','projectname','12-12-20','empty'],
['34','ready','projectname','12-12-20','empty'],
['34','ready','projectname','12-12-20','empty'],
[
['34','ready','projectname','12-12-20','jerry'],
['34','ready','projectname','12-12-20','john']
]
];
函数isArrayOfArrays(a){
返回a.every(x=>Array.isArray(x));
}
函数阵列(arr){
常量结果=[];
for(arr的常量元素){
if(isArrayOfArrays(currElement)){
for(让currElement的innerArray){
结果.推送(内部数组);
}
}否则{
结果:推送(电流元件);
}
}
返回结果;
}

日志(数组(arr))数据转换问题应始终包括转换过程的输入和预期输出。请编辑您的问题,将两者都包括在内。为什么要混合可变和不可变操作。只需使用reduce来重建它。多亏了您的解决方法,我重新编写了代码,不再具有innerArray。因此,我消除了问题本身:)