暑假学习第二天
- HTML再巩固了盒模型
- JS今日巩固了map(),filter(),reduce(),apply(),call(),bind()的使用
将一个字符转化为数字的方法:
let f = '1';
let c = f-0;
console.log(parseInt(f));
console.log(c);
把字符串转化为数组['1','2','3','4'] -->[1,2,3,4]
let y = ['1','2','3'];
console.log(y.map(Number));
console.log(y.map(function (x) {
return x -0;
}));
把'1234' -- > [1,2,3,4]
let s = '1234';
let arr1;
arr1 = s.split("").map(function (x) {
return x - 0;
//return parseInt(x);
});
//arr1 = s.split("").map(Number);
console.log(arr1);
把'1234' --> [1,2,3,4] --->1234
arr1 = s.split("").map(Number).reduce(function (x,y){
return x*10+y;});