±¾ÎÄʵÀý½²ÊöÁËJavaScriptÊý×é¼°³£¼û²Ù×÷·½·¨¡£·ÖÏí¸ø´ó¼Ò¹©´ó¼Ò²Î¿¼£¬¾ßÌåÈçÏ£º
Êý×é¼°²Ù×÷·½·¨
Êý×é¾ÍÊÇÒ»×éÊý¾ÝµÄ¼¯ºÏ£¬javascriptÖУ¬Êý×éÀïÃæµÄÊý¾Ý¿ÉÒÔÊDz»Í¬ÀàÐ͵ġ£
¶¨ÒåÊý×éµÄ·½·¨
//¶ÔÏóµÄʵÀý´´½¨ var aList = new Array(1,2,3); //Ö±½ÓÁ¿´´½¨ var aList2 = [1,2,3,'asd'];
²Ù×÷Êý×éÖÐÊý¾ÝµÄ·½·¨
1¡¢»ñÈ¡Êý×éµÄ³¤¶È£ºaList.length;
var aList = [1,2,3,4]; alert(aList.length); // µ¯³ö4
2¡¢ÓÃϱê²Ù×÷Êý×éµÄij¸öÊý¾Ý£ºaList[0];
var aList = [1,2,3,4]; alert(aList[0]); // µ¯³ö1
3¡¢join() ½«Êý×é³ÉԱͨ¹ýÒ»¸ö·Ö¸ô·ûºÏ²¢³É×Ö·û´®
var aList = [1,2,3,4]; alert(aList.join('-')); // µ¯³ö 1-2-3-4
4¡¢push() ºÍ pop() ´ÓÊý×é×îºóÔö¼Ó³ÉÔ±»òɾ³ý³ÉÔ±
var aList = [1,2,3,4]; aList.push(5); alert(aList); //µ¯³ö1,2,3,4,5 aList.pop(); alert(aList); // µ¯³ö1,2,3,4
5¡¢unshift()ºÍ shift() ´ÓÊý×éÇ°ÃæÔö¼Ó³ÉÔ±»òɾ³ý³ÉÔ±
var aList = [1,2,3,4]; aList.unshift(5); alert(aList); //µ¯³ö5,1,2,3,4 aList.shift(); alert(aList); // µ¯³ö1,2,3,4
6¡¢reverse() ½«Êý×鷴ת
var aList = [1,2,3,4]; aList.reverse(); alert(aList); // µ¯³ö4,3,2,1
7¡¢indexOf() ·µ»ØÊý×éÖÐÔªËصÚÒ»´Î³öÏÖµÄË÷ÒýÖµ
var aList = [1,2,3,4,1,3,4]; alert(aList.indexOf(1));
8¡¢splice() ÔÚÊý×éÖÐÔö¼Ó»òɾ³ý³ÉÔ±
var aList = [1,2,3,4]; aList.splice(2,1,7,8,9); //´ÓµÚ2¸öÔªËØ¿ªÊ¼£¬É¾³ý1¸öÔªËØ£¬È»ºóÔÚ´ËλÖÃÔö¼Ó'7,8,9'Èý¸öÔªËØ alert(aList); //µ¯³ö 1,2,7,8,9,4
¶àάÊý×é
¶àάÊý×éÖ¸µÄÊÇÊý×éµÄ³ÉÔ±Ò²ÊÇÊý×éµÄÊý×é¡£
var aList = [[1,2,3],['a','b','c']]; alert(aList[0][1]); //µ¯³ö2;
ÅúÁ¿²Ù×÷Êý×éÖеÄÊý¾Ý£¬ÐèÒªÓõ½Ñ»·Óï¾ä
¸ÐÐËȤµÄÅóÓÑ¿ÉÒÔʹÓÃÔÚÏßHTML/CSS/JavaScript´úÂëÔËÐй¤¾ß£ºhttp://tools.jb51.net/code/HtmlJsRun²âÊÔÉÏÊö´úÂëÔËÐÐЧ¹û¡£
¸ü¶à¹ØÓÚJavaScriptÏà¹ØÄÚÈݸÐÐËȤµÄ¶ÁÕ߿ɲ鿴±¾Õ¾×¨Ì⣺¡¶JavaScriptÊý×é²Ù×÷¼¼ÇÉ×ܽᡷ¡¢¡¶JavaScript±éÀúËã·¨Óë¼¼ÇÉ×ܽᡷ¡¢¡¶javascriptÃæÏò¶ÔÏóÈëÃŽ̡̳·¡¢¡¶JavaScriptÊýѧÔËËãÓ÷¨×ܽᡷ¡¢¡¶JavaScriptÊý¾Ý½á¹¹ÓëËã·¨¼¼ÇÉ×ܽᡷ¼°¡¶JavaScript´íÎóÓëµ÷ÊÔ¼¼ÇÉ×ܽᡷ
Ï£Íû±¾ÎÄËùÊö¶Ô´ó¼ÒJavaScript³ÌÐòÉè¼ÆÓÐËù°ïÖú¡£
转载请注明:谷谷点程序 » JavaScript数组及常见操作方法小结