标签:java class dag people fun push object length reac
var array = [{ "type": "people", "name": "chen", "sex": "男", "age": 30, "objects": [{ "type": "people", "name": "chen", "sex": "男", "age": 31 }, { "type": "people", "name": "chen", "sex": "男", "age": 32 }] }, { "type": "people", "name": "chen", "sex": "男", "age": 33, }, { "type": "people", "name": "chen", "sex": "男", "age": 34, "objects": [{ "type": "people", "name": "chen", "sex": "男", "age": 35 }] }]; var ageAll = []; var findAge = function(arr) { arr.forEach(function(item) { if (item.age) { ageAll.push(item.age); } if (item.objects && item.objects.length > 0) { findAge(item.objects); } }); } findAge(array); console.log(ageAll);
标签:java class dag people fun push object length reac
原文地址:https://www.cnblogs.com/front-boy/p/9299477.html