1¡¢Êý×éµÄ´´½¨
var arrayObj = new Array();¡¡//´´½¨Ò»¸öÊý×é
var arrayObj = new Array([size]);¡¡//´´½¨Ò»¸öÊý×é²¢Ö¸¶¨³¤¶È£¬×¢Òâ²»ÊÇÉÏÏÞ£¬Êdz¤¶È
var arrayObj = new Array([element0[, element1[, ...[, elementN]]]]);¡¡//´´½¨Ò»¸öÊý×é²¢¸³Öµ
Ҫ˵Ã÷µÄÊÇ£¬ËäÈ»µÚ¶þÖÖ·½·¨´´½¨Êý×éÖ¸¶¨Á˳¤¶È£¬µ«Êµ¼ÊÉÏËùÓÐÇé¿öÏÂÊý×鶼ÊDZ䳤µÄ£¬Ò²¾ÍÊÇ˵¼´Ê¹Ö¸¶¨Á˳¤¶ÈΪ5£¬ÈÔÈ»¿ÉÒÔ½«ÔªËØ´æ´¢Ôڹ涨³¤¶ÈÒÔÍâµÄ£¬×¢Ò⣺Õâʱ³¤¶È»áËæÖ®¸Ä±ä¡£
2¡¢Êý×éµÄÔªËصķÃÎÊ
var testGetArrValue=arrayObj[1]; //»ñÈ¡Êý×éµÄÔªËØÖµ
arrayObj[1]= "ÕâÊÇÐÂÖµ"; //¸øÊý×éÔªËظ³ÓèеÄÖµ
3¡¢Êý×éÔªËصÄÌí¼Ó
´úÂë
arrayObj. push([item1 [item2 [. . . [itemN ]]]]);// ½«Ò»¸ö»ò¶à¸öÐÂÔªËØÌí¼Óµ½Êý×é½á⣬²¢·µ»ØÊý×é㤶È
arrayObj.unshift([item1 [item2 [. . . [itemN ]]]]);// ½«Ò»¸ö»ò¶à¸öÐÂÔªËØÌí¼Óµ½Êý×鿪ʼ£¬Êý×éÖеÄÔªËØ×Ô¶¯ºóÒÆ£¬·µ»ØÊý×é㤶È
arrayObj.splice(insertPos,0,[item1[, item2[, . . . [,itemN]]]]);//½«Ò»¸ö»ò¶à¸öÐÂÔªËزåÈëµ½Êý×éµÄÖ¸¶¨Î»Ö㬲åÈëλÖõÄÔªËØ×Ô¶¯ºóÒÆ£¬·µ»Ø""¡£
4¡¢Êý×éÔªËصÄɾ³ý
arrayObj.pop(); //ÒƳý×îºóÒ»¸öÔªËز¢·µ»Ø¸ÃÔªËØÖµ
arrayObj.shift(); //ÒƳý×îÇ°Ò»¸öÔªËز¢·µ»Ø¸ÃÔªËØÖµ£¬Êý×éÖÐÔªËØ×Ô¶¯Ç°ÒÆ
arrayObj.splice(deletePos,deleteCount); //ɾ³ý´ÓÖ¸¶¨Î»ÖÃdeletePos¿ªÊ¼µÄÖ¸¶¨ÊýÁ¿deleteCountµÄÔªËØ£¬Êý×éÐÎʽ·µ»ØËùÒƳýµÄÔªËØ
5¡¢Êý×éµÄ½ØÈ¡ºÍºÏ²¢
arrayObj.slice(start, [end]); //ÒÔÊý×éµÄÐÎʽ·µ»ØÊý×éµÄÒ»²¿·Ö£¬×¢Òâ²»°üÀ¨ end ¶ÔÓ¦µÄÔªËØ£¬Èç¹ûÊ¡ÂÔ end ½«¸´ÖÆ start Ö®ºóµÄËùÓÐÔªËØ
arrayObj.concat([item1[, item2[, . . . [,itemN]]]]); //½«¶à¸öÊý×飨Ҳ¿ÉÒÔÊÇ×Ö·û´®£¬»òÕßÊÇÊý×éºÍ×Ö·û´®µÄ»ìºÏ£©Á¬½ÓΪһ¸öÊý×飬·µ»ØÁ¬½ÓºÃµÄеÄÊý×é
6¡¢Êý×éµÄ¿½±´
arrayObj.slice(0); //·µ»ØÊý×éµÄ¿½±´Êý×飬עÒâÊÇÒ»¸öеÄÊý×飬²»ÊÇÖ¸Ïò
arrayObj.concat(); //·µ»ØÊý×éµÄ¿½±´Êý×飬עÒâÊÇÒ»¸öеÄÊý×飬²»ÊÇÖ¸Ïò
7¡¢Êý×éÔªËصÄÅÅÐò
arrayObj.reverse(); //·´×ªÔªËØ£¨×îÇ°µÄÅŵ½×îºó¡¢×îºóµÄÅŵ½×îÇ°£©£¬·µ»ØÊý×éµØÖ·
arrayObj.sort(); //¶ÔÊý×éÔªËØÅÅÐò£¬·µ»ØÊý×éµØÖ·
8¡¢Êý×éÔªËصÄ×Ö·û´®»¯
arrayObj.join(separator); //·µ»Ø×Ö·û´®£¬Õâ¸ö×Ö·û´®½«Êý×éµÄÿһ¸öÔªËØÖµÁ¬½ÓÔÚÒ»Æð£¬ÖмäÓà separator ¸ô¿ª¡£
toLocaleString ¡¢toString ¡¢valueOf£º¿ÉÒÔ¿´×÷ÊÇjoinµÄÌØÊâÓ÷¨£¬²»³£ÓÃ
¶þ¡¢Êý×é¶ÔÏóµÄ3¸öÊôÐÔ
1¡¢length ÊôÐÔ
LengthÊôÐÔ±íʾÊý×éµÄ³¤¶È£¬¼´ÆäÖÐÔªËصĸöÊý¡£ÒòΪÊý×éµÄË÷Òý×ÜÊÇÓÉ0¿ªÊ¼£¬ËùÒÔÒ»¸öÊý×éµÄÉÏÏÂÏÞ·Ö±ðÊÇ£º0ºÍlength-1¡£ºÍÆäËû´ó¶àÊýÓïÑÔ²»Í¬µÄÊÇ£¬JavaScriptÊý×éµÄlengthÊôÐÔÊǿɱäµÄ£¬ÕâÒ»µãÐèÒªÌرð×¢Òâ¡£µ±lengthÊôÐÔ±»ÉèÖõøü´óʱ£¬Õû¸öÊý×éµÄ״̬ÊÂʵÉϲ»»á·¢Éú±ä»¯£¬½ö½öÊÇlengthÊôÐÔ±ä´ó£»µ±lengthÊôÐÔ±»ÉèÖõñÈÔÀ´Ð¡Ê±£¬ÔòÔÏÈÊý×éÖÐË÷Òý´óÓÚ»òµÈÓÚlengthµÄÔªËصÄֵȫ²¿±»¶ªÊ§¡£ÏÂÃæÊÇÑÝʾ¸Ä±älengthÊôÐÔµÄÀý×Ó£º
var arr=[12,23,5,3,25,98,76,54,56,76];//¶¨ÒåÁËÒ»¸ö°üº¬10¸öÊý×ÖµÄÊý×éalert(arr.length); //ÏÔʾÊý×éµÄ³¤¶È10arr.length=12; //Ôö´óÊý×éµÄ³¤¶Èalert(arr.length); //ÏÔʾÊý×éµÄ³¤¶ÈÒѾ±äΪ12alert(arr[8]); //ÏÔʾµÚ9¸öÔªËصÄÖµ£¬Îª56arr.length=5; //½«Êý×éµÄ³¤¶È¼õÉÙµ½5£¬Ë÷ÒýµÈÓÚ»ò³¬¹ý5µÄÔªËر»¶ªÆúalert(arr[8]); //ÏÔʾµÚ9¸öÔªËØÒѾ±äΪ"undefined"arr.length=10; //½«Êý×鳤¶È»Ö¸´Îª10alert(arr[8]); //ËäÈ»³¤¶È±»»Ö¸´Îª10£¬µ«µÚ9¸öÔªËØÈ´ÎÞ·¨Êջأ¬ÏÔʾ"undefined"
ÓÉÉÏÃæµÄ´úÂëÎÒÃÇ¿ÉÒÔÇå³þµÄ¿´µ½lengthÊôÐÔµÄÐÔÖÊ¡£µ«length¶ÔÏó²»½ö¿ÉÒÔÏÔʽµÄÉèÖã¬ËüÒ²ÓпÉÄܱ»ÒþʽÐ޸ġ£JavaScriptÖпÉÒÔʹÓÃÒ»¸öδÉùÃ÷¹ýµÄ±äÁ¿£¬Í¬Ñù£¬Ò²¿ÉÒÔʹÓÃÒ»¸ö䶨ÒåµÄÊý×éÔªËØ£¨Ö¸Ë÷Òý³¬¹ý»òµÈÓÚlengthµÄÔªËØ£©£¬Õâʱ£¬lengthÊôÐÔµÄÖµ½«±»ÉèÖÃΪËùʹÓÃÔªËØË÷ÒýµÄÖµ¼Ó1¡£ÀýÈçÏÂÃæµÄ´úÂ룺
var arr=[12,23,5,3,25,98,76,54,56,76];
alert(arr.length);
arr[15]=34;
alert(arr.length);
´úÂëÖÐͬÑùÊÇÏȶ¨ÒåÁËÒ»¸ö°üº¬10¸öÊý×ÖµÄÊý×飬ͨ¹ýalertÓï¾ä¿ÉÒÔ¿´³öÆ䳤¶ÈΪ10¡£ËæºóʹÓÃÁËË÷ÒýΪ15µÄÔªËØ£¬½«Æ丳ֵΪ15£¬¼´ arr[15]=34£¬ÕâʱÔÙÓÃalertÓï¾äÊä³öÊý×éµÄ³¤¶È£¬µÃµ½µÄÊÇ16¡£ÎÞÂÛÈçºÎ£¬¶ÔÓÚÏ°¹ßÓÚÇ¿ÀàÐͱà³ÌµÄ¿ª·¢ÈËÔ±À´Ëµ£¬ÕâÊÇÒ»¸öºÜÁîÈ˾ªÑȵÄÌØÐÔ¡£ÊÂʵÉÏ£¬Ê¹ÓÃnew Array()ÐÎʽ´´½¨µÄÊý×飬Æä³õʼ³¤¶È¾ÍÊÇΪ0£¬ÕýÊǶÔÆäÖÐ䶨ÒåÔªËصIJÙ×÷£¬²ÅʹÊý×éµÄ³¤¶È·¢Éú±ä»¯¡£
ÓÉÉÏÃæµÄ½éÉÜ¿ÉÒÔ¿´µ½£¬lengthÊôÐÔÊÇÈç´ËµÄÉñÆ棬ÀûÓÃËü¿ÉÒÔ·½±ãµÄÔö¼Ó»òÕß¼õÉÙÊý×éµÄÈÝÁ¿¡£Òò´Ë¶ÔlengthÊôÐÔµÄÉîÈëÁ˽⣬ÓÐÖúÓÚÔÚ¿ª·¢¹ý³ÌÖÐÁé»îÔËÓá£
2¡¢prototype ÊôÐÔ
·µ»Ø¶ÔÏóÀàÐÍÔÐ͵ÄÒýÓá£prototype ÊôÐÔÊÇ object ¹²Óеġ£
objectName.prototype
objectName ²ÎÊýÊÇobject¶ÔÏóµÄÃû³Æ¡£
˵Ã÷£ºÓà prototype ÊôÐÔÌṩ¶ÔÏóµÄÀàµÄÒ»×é»ù±¾¹¦ÄÜ¡£ ¶ÔÏóµÄÐÂʵÀý“¼Ì³Ð”¸³Óè¸Ã¶ÔÏóÔÐ͵IJÙ×÷¡£
¶ÔÓÚÊý×é¶ÔÏó£¬ÒÔÒÔÏÂÀý×Ó˵Ã÷prototype ÊôÐÔµÄÓÃ;¡£
¸øÊý×é¶ÔÏóÌí¼Ó·µ»ØÊý×éÖÐ×î´óÔªËØÖµµÄ·½·¨¡£ÒªÍê³ÉÕâÒ»µã£¬ÉùÃ÷Ò»¸öº¯Êý£¬½«Ëü¼ÓÈë Array.prototype£¬ ²¢Ê¹ÓÃËü¡£
function array_max(){var i,max = this[0];for (i = 1; i < this.length; i++){if (max < this[i])max = this[i];}return max;}Array.prototype.max = array_max;var x = new Array(1, 2, 3, 4, 5, 6);var y = x.max();
¸Ã´úÂëÖ´Ðкó£¬y ±£´æÊý×é x ÖеÄ×î´óÖµ£¬»ò˵ 6¡£
3¡¢constructor ÊôÐÔ
±íʾ´´½¨¶ÔÏóµÄº¯Êý¡£
object.constructor //objectÊǶÔÏó»òº¯ÊýµÄÃû³Æ¡£
˵Ã÷£ºconstructor ÊôÐÔÊÇËùÓоßÓÐ prototype µÄ¶ÔÏóµÄ³ÉÔ±¡£ËüÃÇ°üÀ¨³ý Global ºÍ Math ¶ÔÏóÒÔÍâµÄËùÓÐ JScript ¹ÌÓжÔÏó¡£constructor ÊôÐÔ±£´æÁ˶Թ¹ÔìÌض¨¶ÔÏóʵÀýµÄº¯ÊýµÄÒýÓá£
ÀýÈ磺
x = new String("Hi");if (x.constructor == String) // ½øÐд¦Àí£¨Ìõ¼þΪÕ棩¡£»òfunction MyFunc {// º¯ÊýÌå¡£}y = new MyFunc;if (y.constructor == MyFunc) // ½øÐд¦Àí£¨Ìõ¼þΪÕ棩¡£
¶ÔÓÚÊý×éÀ´Ëµ£º
y = new Array();
±¾Õ¾»¶ÓÈκÎÐÎʽµÄתÔØ£¬µ«ÇëÎñ±Ø×¢Ã÷³ö´¦£¬×ðÖØËûÈËÀͶ¯³É¹û
תÔØÇë×¢Ã÷£º ÎÄÕÂתÔØ×Ô£º°®Ë¼×ÊÔ´Íø http://www.aseoe.com/show-12-593-1.html
תÔØÇë×¢Ã÷£º ÎÄÕÂתÔØ×Ô£º°®Ë¼×ÊÔ´Íø http://www.aseoe.com/show-12-593-1.html