¡¾ÒëÕß×¢£ºÌØÒâ²éÁËÒ»ÏÂMath.random()Éú³É 0 µ½ 1 Ö®¼äµÄËæ»úÊý£¬number.toString(36) Êǽ«Õâ¸öÊý×Öת»»³É36½øÖÆ£¨0-9£¬a-z£©£¬×îºó`substr È¥µôÇ°ÃæµÄ¡°0.¡±×Ö·û´®¡¿
12. ´òÂÒÒ»¸öÊý×ÖÊý×évar numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411]; numbers = numbers.sort( function(){ return Math.random() - 0.5 });/* the array numbers will be equal for example to [120, 5, 228, -215, 400, 458, -85411, 122205] */13. StringµÄtrimº¯ÊýÔÚJava¡¢C#¡¢PHPºÍºÜ¶àÆäËûÓïÑÔÖж¼ÓÐÒ»¸ö¾µäµÄ trim º¯Êý£¬ÓÃÀ´È¥³ý×Ö·û´®ÖеĿոñ·û£¬¶øÔÚJavaScriptÖв¢Ã»ÓУ¬ËùÒÔÎÒÃÇÐèÒªÔÚString¶ÔÏóÉϼÓÉÏÕâ¸öº¯Êý¡£
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g, "");};ÒëÕß×¢£ºÈ¥µô×Ö·û´®µÄÇ°ºó¿Õ¸ñ£¬²»°üÀ¨×Ö·û´®ÄÚ²¿¿Õ¸ñ
14. ¸½¼Ó£¨append£©Ò»¸öÊý×éµ½ÁíÒ»¸öÊý×éÉÏvar array1 = [12 , "foo" , {name: "Joe"} , -2458]; var array2 = ["Doe" , 555 , 100]; Array.prototype.push.apply(array1, array2); /* array1 will be equal to [12 , "foo" , {name "Joe"} , -2458 , "Doe" , 555 , 100] */ÒëÕß×¢£ºÆäʵconcat¿ÉÒÔÖ±½ÓʵÏÖÁ½¸öÊý×éµÄÁ¬½Ó£¬µ«ÊÇËüµÄ·µ»ØÖµÊÇÒ»¸öеÄÊý×é¡£ÕâÀïÊÇÖ±½Ó¸Ä±äarray1
15. ½«arguments¶ÔÏóת»»³ÉÒ»¸öÊý×évar argArray = Array.prototype.slice.call(arguments);ÒëÕß×¢£ºarguments ¶ÔÏóÊÇÒ»¸öÀàÊý×é¶ÔÏ󣬵«²»ÊÇÒ»¸öÕæÕýµÄÊý×é
16. ÑéÖ¤²ÎÊýÊÇ·ñÊÇÊý×Ö£¨number£©function isNumber(n){ return !isNaN(parseFloat(n)) && isFinite(n); }17. ÑéÖ¤²ÎÊýÊÇ·ñÊÇÊý×éfunction isArray(obj){ return Object.prototype.toString.call(obj) === '[object Array]' ; }×¢Ò⣺Èç¹û toString() ·½·¨±»ÖØдÁË£¨overridden£©£¬ÄãʹÓÃÕâ¸ö¼¼ÇɾͲ»Äܵõ½ÏëÒªµÄ½á¹ûÁË¡£»òÕßÄã¿ÉÒÔʹÓãº
Array.isArray(obj); // ÕâÊÇÒ»¸öеÄarrayµÄ·½·¨Èç¹ûÄã²»ÔÚʹÓöàÖØframesµÄÇé¿öÏ£¬Ä㻹¿ÉÒÔʹÓà instanceof ·½·¨¡£µ«Èç¹ûÄãÓжà¸öÉÏÏÂÎÄ£¬Äã¾Í»áµÃµ½´íÎóµÄ½á¹û¡£
var myFrame = document.createElement('iframe');document.body.appendChild(myFrame); var myArray = window.frames[window.frames.length-1].Array;var arr = new myArray(a,b,10); // [a,b,10] // instanceof will not work correctly, myArray loses his constructor// constructor is not shared between framesarr instanceof Array; // falseÒëÕß×¢£º¹ØÓÚÈçºÎÅжÏÊý×éÍøÉÏÓв»ÉÙÌÖÂÛ£¬´ó¼Ò¿ÉÒÔgoogleһϡ£Õâƪ¾ÍдµÄͦÏêϸµÄ¡£
18. »ñÈ¡Ò»¸öÊý×ÖÊý×éÖеÄ×î´óÖµ»ò×îСֵvar numbers = [5, 458 , 120 , -215 , 228 , 400 , 122205, -85411]; var maxInNumbers = Math.max.apply(Math, numbers); var minInNumbers = Math.min.apply(Math, numbers);ÒëÕß×¢£ºÕâÀïʹÓÃÁËFunction.prototype.apply·½·¨´«µÝ²ÎÊýµÄ¼¼ÇÉ
19. Çå¿ÕÒ»¸öÊý×évar myArray = [12 , 222 , 1000 ]; myArray.length = 0; // myArray will be equal to [].20. ²»ÒªÊ¹Óà delete À´É¾³ýÒ»¸öÊý×éÖеÄÏʹÓà splice ¶ø²»ÒªÊ¹Óà delete À´É¾³ýÊý×éÖеÄij¸öÏʹÓà delete Ö»ÊÇÓà undefined À´Ìæ»»µôÔÓеÄÏ²¢²»ÊÇÕæÕýµÄ´ÓÊý×éÖÐɾ³ý¡£
²»ÒªÊ¹ÓÃÕâÖÖ·½Ê½£º
var items = [12, 548 ,'a' , 2 , 5478 , 'foo' , 8852, , 'Doe' ,2154 , 119 ]; items.length; // return 11delete items[3]; // return trueitems.length; // return 11/* items will be equal to [12, 548, "a", undefined ¡Á 1, 5478, "foo", 8852, undefined ¡Á 1, "Doe", 2154, 119] */
¡¡