简体   繁体   English

如何在另一个数组 JS 中取消移动数组?

[英]How to unshift an Array in another Array JS?

Is there a way to unshift an Array in another Array?有没有办法在另一个数组中取消移动数组?

I have an Array-of-Arrays我有一个数组数组

[["Sunny", "Hot", "High", "Weak", "No"],
["Sunny", "Hot", "High", "Strong", "No"]]

and all I am trying to accomplish is to add another Array我想要完成的就是添加另一个数组

["Outlook", "Temperature", "Humidity", "Wind", "Play-ball"]

on top of the Array-of-Arrays, so that the final Array would look like this在 Array-of-Arrays 之上,以便最终的 Array 看起来像这样

[["Outlook", "Temperature", "Humidity", "Wind", "Play-ball"],
["Sunny", "Hot", "High", "Weak", "No"],
["Sunny", "Hot", "High", "Strong", "No"]]

unshift() only adds an empty Array on top of the Array-of-Arrays, so I guess it works only for items in a single Array, is there an unshift equivalent for Arrays? unshift() 只在 Array-of-Arrays 之上添加一个空数组,所以我猜它只适用于单个数组中的项目,是否有一个 unshift 等效的数组?

You could unshift an array as an item.您可以将数组取消移动为项目。

 var array = [["Sunny", "Hot", "High", "Weak", "No"], ["Sunny", "Hot", "High", "Strong", "No"]], another = ["Outlook", "Temperature", "Humidity", "Wind", "Play-ball"]; array.unshift(another); console.log(array);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM