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
[["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?
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.