動車臥鋪有幾層鋪(動車臥鋪有幾層?)
2024-01-22
更新時間:2024-01-23 00:06:09作者:未知
今天,我們來一起學(xué)習(xí)一下如何把元素添加到元素的首個元素。
letfruits=["Apple","Banana","Mango"];fruits.unshift("Orange");console.log(fruits);//Prints["Orange","Apple","Banana","Mango"]fruits.unshift("Guava","Papaya");console.log(fruits);//Prints["Guava","Papaya","Orange","Apple","Banana","Mango"]
varfruits=["Apple","Banana","Mango"];varmoreFruits=["Orange",...fruits];console.log(moreFruits);//Prints["Orange","Apple","Banana","Mango"]varsomeoMoreFruits=["Guava","Papaya",...moreFruits];console.log(someoMoreFruits);//Prints["Guava","Papaya","Orange","Apple","Banana","Mango"]console.log(fruits);//Prints["Apple","Banana","Mango"]
我們還可以使用concat()方法在開頭連接兩個(或更多)數(shù)組。
varfruits=["Apple","Banana","Mango"];varmoreFruits=["Orange"];varsomeoMoreFruits=["Guava","Papaya"];varallFruits=someoMoreFruits.concat(moreFruits,fruits);console.log(allFruits);//Prints["Guava","Papaya","Orange","Apple","Banana","Mango"]
完~我是小智,我要去刷碗了,我們下期再見~
ps:【項目】淘寶項目邀請用戶即可獲取收益
ps:【活動】支付寶大額紅包點擊掃碼領(lǐng)取
ps:【本站主題】自適應(yīng)資訊類的網(wǎng)站主題