Created
May 29, 2014 10:24
-
-
Save youxiachai/ccdcffc2fb2aa7fb9e6c to your computer and use it in GitHub Desktop.
js 数组练习
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var newArray = ['1','2','3','4'].map(function (item){ | |
return item | |
}).reduce(function (x, y){ | |
if(Array.isArray(x)){ | |
return x.concat(y) | |
}else{ | |
var arr = []; | |
arr.push(x) | |
return arr; | |
} | |
}).filter(function (z) { | |
return z; | |
}) | |
console.log(newArray) |
@ylxs90 有人留言好高兴啊... 笑哥..看懂这几行代码没..js 数组普通使用..
js reduce 的使用.. 问 x1 打印结果
var x1 = [1,2,3,4,5].reduce(function (x, y){
return x+y;
})
console.log(x1);
提示:
reduce 的定义 x,y:x+y
((((1+2)+3)+4)+5)
表示还需要努力
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
欺负我没见过这几个方法?fuck