javascript中数组的强大用法·

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 - 

  

上一篇:ZOJ 1151 Word Reversal反转单词 (string字符串处理)


下一篇:C#中数组Array、ArrayList、泛型List的比较