array in javascript
Array
1. sort & reverse
e.g. :
var a2=[10,2,3,1,7];
a2.reverse();// 7,1,3,2,10
a2.sort();//1,10,2,3,7
function compare(value1,value2){
if(value1<value2){return -1;}
else if(value1>value2){return 1;}
else{return 0;}
}
a2.sort(compare);// 1,2,3,7,10
function getType(obj){
let type= typeof obj;
if(type!=='object'){return type;}
return Object.prototype.toString.call(obj).replace(/^\[object (\S+)\]$/,'$1'); // [object Number]
}
var x = 15 * 5;
getType(x); // Number
评论
发表评论