×ðÁú¿­Ê±¹ÙÍøµÇ¼

jsÊý×éÖÐÔõô²åÈ빤¾ß

Ïò javascript Êý×éÖвåÈ빤¾ßÓÐÁ½ÖÖÒªÁ죺һÊÇʹÓà push() ÒªÁìÌí¼ÓÖµµ½Êý×éĩ⣬¶þÊÇʹÓà spread ÔËËã·û½«¹¤¾ß²ð½â³ÉÔªËز¢Ìí¼Óµ½Êý×éÖС£

ÔõÑùÏò JavaScript Êý×éÖвåÈ빤¾ß

ÔÚ JavaScript ÖУ¬ÏòÊý×éÖвåÈ빤¾ßÓÐÒÔÏÂÁ½ÖÖ³£¼ûÒªÁ죺

1. ʹÓà push() ÒªÁì

push() ÒªÁ콫һ¸ö»ò¶à¸öÖµÌí¼Óµ½Êý×éµÄĩβ¡£ÒªÏòÊý×éÖвåÈëÒ»¸ö¹¤¾ß£¬¿ÉÒÔ½«¹¤¾ß×÷Ϊ²ÎÊýת´ï¸ø push() ÒªÁ죺

let arr = ['a', 'b', 'c'];
arr.push({name: 'John', age: 30});

µÇ¼ºó¸´ÖÆ

Ö´ÐдúÂëºó£¬arr Êý×齫ÈçÏÂËùʾ£º

['a', 'b', 'c', {name: 'John', age: 30}]

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

2. ʹÓà spread ÔËËã·û£¨…£©

spread ÔËËã·û¿ÉÒÔ½«Ò»¸ö¹¤¾ß²ð½â³ÉÒ»¸ö¸öÔªËØ£¬²¢½«ÆäÌí¼Óµ½Êý×éÖС£Òª½«¹¤¾ß²åÈëÊý×飬¿ÉÒÔʹÓÃÒÔÏÂÓï·¨£º

let arr = ['a', 'b', 'c'];
arr = [...arr, {name: 'John', age: 30}];

µÇ¼ºó¸´ÖÆ

Ö´ÐдúÂëºó£¬arr Êý×齫ÈçÏÂËùʾ£º

['a', 'b', 'c', {name: 'John', age: 30}]

µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ

ÒÔÉϾÍÊÇjsÊý×éÖÐÔõô²åÈ빤¾ßµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ