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
显示无限数量的未定义数组,javascript_Javascript_Arrays_Json_Concatenation - Fatal编程技术网

显示无限数量的未定义数组,javascript

显示无限数量的未定义数组,javascript,javascript,arrays,json,concatenation,Javascript,Arrays,Json,Concatenation,指: 我试图显示一个由无限多个对象数组创建的数组,有些数组可能未定义。 有没有更好的写作方法。 我对那个问题的解决方案看起来不专业 const theFunction = () => { let EveryArrayGoesHere = [] try { EveryArrayGoesHere = EveryArrayGoesHere.concat(array1, array2, array3 ...) if (EveryArrayGoesHe

指:

我试图显示一个由无限多个对象数组创建的数组,有些数组可能未定义。 有没有更好的写作方法。 我对那个问题的解决方案看起来不专业

const theFunction = () => {
    let EveryArrayGoesHere = []
    try {
        EveryArrayGoesHere = EveryArrayGoesHere.concat(array1, array2, array3 ...)
        if (EveryArrayGoesHere) {
            EveryArrayGoesHere = JSON.stringify(EveryArrayGoesHere)
            EveryArrayGoesHere = EveryArrayGoesHere.replace('null,', '')
            EveryArrayGoesHere = EveryArrayGoesHere.replace(',null', '')
            return JSON.parse(EveryArrayGoesHere);
        } else {
            return 'data not availible';
        }
    } catch (e) {
        if (e) {
            console.error('data error', e.message)
        }
    }
}
console.log('array of objects:',theFunction() )

我希望我正确理解了你的问题

var收集器=[];
风险值数据=[
[1,2,3],
未定义,
[4,5,6],
[7,8],
未定义,
[9]  
];
//log('data=>',data);
data=data.filter(v=>{returnarray.isArray(v)}).forEach(a=>{collector=collector.concat(a)});

log('collector=>',collector)某些数组可能未定义或某些对象?数组可能未定义,thanksmay数组可能只包含未定义的值,即[undefined,undefined]…解决方案适用于包含对象“[{”product:“apple”,“trueFalse”:true,“price”:1.5},{”product:“banana”的数组,“trueFalse”:true,“price”:1}]`此解决方案可能适用于具有类似结构的数组。`Array.isArray`完成此工作,谢谢@Reflective