1 归并
var a = [{name: 'tom'},{name: 'aiscy'},{name: 'judy'},{name: 'mike'}];
a.reduce(function(prev, item) {console.log(prev);return item.name + ' ' + prev;}, ''); // tom - aiscy - judy - mike
2. 迭代
var children = [{name: 'father', childs: [{name: 'child1', childs: [{name: 'child2'}]}]}]; function getText(array) { arguments;
if (array) {
var res = array[0].name + ' - ' + arguments.callee(array[0].childs);
return res;
}
return ''; } var s1 = getText(children);
console.log(s1); // 返回father - child1 - child2 -