JavaScript提取数组内所有元素

var arrN = [[[1, "wangyuchu", 54, [123, 34, [123, 34, 16]]],"zhangsan", 25, [1, "wangyuchu", 54, [123, 34, [123, 34, [1, "wangyuchu", 54, [123, 34, [123, 34, 16]]],]]], 43], ["lisi", 21, 172], ["wangwu", 32, "suzhou"]];

var arrgroup=[];
function recursion(obj) {
    if (typeof obj==='object') {
        for (var j in obj) {
            if (typeof obj[j]!=='object') {
                arrgroup.push(obj[j]);
                continue;
            }
            recursion(obj[j]);
        }
    } else {
        arrgroup.push(obj);
    }
    return arrgroup;
}
console.log(recursion(arrN));

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注