// ============ isarray ===============// // isarray function IsArray (value) { return Object.prototype.toString.call (value) = = "[Object] Array] "; } var arr = [1,2,3,4,5]; // IE8 and below are not supported
//============ Filter and other ===============// //Some methods of array every (), filter (), ForEach (), map (), some () //IE8 and below are not supported //solution, take filter as an example and write a filter if(!Array.prototype.filter) {Array.prototype.filter=function(Fun/*, Thisp*/){ varLen = This. Length; if(typeofFun! = "function"){ Throw NewTypeError (); } varres =NewArray (); varThisp = arguments[1]; for(vari = 0; i < Len; i++){ if(Iinch This){ varval = This[i];//In case fun mutates this if(Fun.call (Thisp, Val, I, This) {Res.push (val); } } } returnRes; }; } varnumbers = [1,2,3,4,5,6]; varFilterresult = Numbers.filter (function(item, Inde, array) {return(item>2); }); alert (Filterresult); //3,4,5,6
// ============ Date.now () ===============// // date.now (); IE8 and below do not support, can only write a solution if(! ) Date.now) { function() { returnnew Date (). ValueOf (); } } Alert (Date.now ());
// ============ stringvalue[1] ============ ===// // show IE7 in undefined and the following versions var stringvalue = "Hello World" ; Alert (stringvalue[ 1
// ============ trim () ===============// // in IE8 and the following versions are invalid and need to be written by yourself function() { returnthis. Replace (/(^\s*) (\s*$)/g, "") ; }; var stringValue2 = " Hello world "; Alert (Stringvalue2.trim ());
JavaScript some functions not supported under IE summary