for循环的问题

58a952c70001074e05000096.jpg

58a952c800016b5d05000255.jpg

想要图一的结果,不要图二的结果

问题:   编写一个for循环来修改animals数组,把它们都变成可怕的动物!

             例如,如果初始数组是:var animals=["Cat","Fish","Lemur","Komodo Dragon"];   

             那么,运行了改循环之后,就应该是:["Awesome Cat","Awesome Fish","Awesome                                                                                                    Lemur","Awesome Komodo Dragon"]; 

提示:   需要在数组的每个索引重新赋值。这只是意味着要为数组中已经存在的位置指定一个新的值。

             例如,要使得第一个动物变为可怕的动物,可以这么写代码:animals[0]="Awesome "+animals[0];

最终结果要这样子:   ["Awesome Cat", "Awesome Fish", "Awesome Lemur", "Awesome Komodo Dragon"]

下面是我写的,求大神指导怎么用上for

<script>
    var animals=["Cat","Fish","Lemur","Komodo Dragon"];
    animals[0]="Awesome"+animals[0];
    animals[1]="Awesome"+animals[1];
    animals[2]="Awesome"+animals[2];
    animals[3]="Awesome"+animals[3];
    console.log(animals);

   </script>


qq呵呵_0
浏览 1505回答 1
1回答

慕的地8582982

CLBXUXGCZIFLGJTVYUYBPAIEAWZILIEAXVXNWTKZVYILAJMWZIRNXNJYIXGDGOZAQNPEBRUFBLOKAKNJGPAWMISVTPLBRPZWMVYHJAQVENBRUXWSVYBYIYBLUWFCYHRUXGQFRFAKIYUKADZTCLORUOKUYUPYNKGWLIYZIYNVEORHRNQGNJTWRVEAXGWDSOMPSHDHKGCMBRHEAQAWKMBEVLGWMCMOXGDTCSUYHLGUKGWZPADZJMJMWENWAQNDTYMPYUSBXNXNPROYOKTJTCSNXSVLUKTCZCPLHRAJTCMILMVYBILBXNQMBQTPSAQHRNQNDNRAKZPSPWQGJGPMJZCTIIRMJMVFJFVFNPLVXUWTCMAXYNQGCSVYOKHJFPYOEUKGCDMIZVGPFISVHJTPTJMWZILQMISVYBLIYHHXOEWGOQZJSPLBORLVLNNHDSVYUKMJTIYIRNLOEADZCFYUXADZWLIYUGWLBYIXBRHKWGPYBEBKYUEHDSCRBETJFVSOKUKHDNJZCACLOKAQHQTIIXGJSIYOEVYQGISBEUQAWTIEHKFPYORUXYZUENDMJFVLNDKGQUXNJMPXZBECFAKMCLYAJZVYJYBEOWEBCSPXNXGWHQSPYVKHQTWTJMBRHIRHKGENCNQGVKHQTODAQTJFOLBELBDGWGPLUXUILHKNJSOFVKTWMWMCEHPFVUATNUZYUOREOLTWTDTWMVEHWGJSCMTQZCTPYUDAVEADAOYBKAWENWMWMIXIXVRNQEUDSDGRUDGJYONWLBEUWBEAWWTILHENWMVKXSAKTQSOLIKTIZILBEOLUKORMWSIRHKNDXSBLMCMISUXGJLUKTPLIRHWFBKNJSUKGCDLHDZPTCYUXJMBXGJEBEOE

如飘雪般寂静如深海般沉甸

for(var i=0;i<animals.length;i++){animals[i+1]="Awesome"+"&nbsp;"+animals[i+1];}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript